0

I need to only run the foreach on iterations that find a currency symbol. Currently, I have this -

$transferid = $key;
$donation1 = $value["news"];
$donationcomma = getStringBetween($donation1,$from,$to);
$donation = str_replace(',', '', $donationcomma);
$playeridregex = preg_match("/XID=(.*)\"/", $donation1, $playerid);
$playerid1 = preg_replace("/[^A-Za-z0-9'-]/","",$playerid[1]);

which I can in turn get the player ID from the string

<a href = "http://www..com/.php?XID=1826888">saeed</a> donated $800,000,000 to the faction

However, as it stands, I need to only check strings that include the money donation, $800,000,000.

Included in the output can be such things as

 <a href = "http://www..com/.php?XID=2023426">French_</a> donated 1 x First Aid Kit to the faction

I need to not run the foreach info on strings such as this.

saeed
  • 13
  • 3
  • [_**Don't use RegEx, use an XML Parser.**_](http://stackoverflow.com/a/1732454/510036) – Qix - MONICA WAS MISTREATED Oct 18 '16 at 19:22
  • The issue is not regex. I need to run an if statement within the foreach to check if the line has a $ symbol, otherwise don't run the foreach on it. – saeed Oct 18 '16 at 19:24
  • @saeed, why don't you use a regexp like \^\$(.+)\ to check if a string starts with a $ or simply the php function $string.startsWith('$'); and continue your operation with the results ? – Nicolas Oct 18 '16 at 19:25
  • If you just need to check if the string contains a `$`, http://php.net/manual/en/function.strpos.php. – chris85 Oct 18 '16 at 19:33
  • To solve this problem you need to learn and use XPath. Use the keyword "donated" for example. – Casimir et Hippolyte Oct 18 '16 at 23:51

1 Answers1

0

from what i understand, you could do something like this :

<?php
foreach($values AS $key=>$value) {
    if(preg_match('/^(\$)(.+)/', $value) == 1) { 
        $transferid = $key;
        $donation1 = $value["news"];
        $donationcomma = getStringBetween($donation1,$from,$to);
        $donation = str_replace(',', '', $donationcomma);
        $playeridregex = preg_match("/XID=(.*)\"/", $donation1, $playerid);
        $playerid1 = preg_replace("/[^A-Za-z0-9'-]/","",$playerid[1]);
    }
}

But still, i'm not sure what you are looking for.

Nicolas
  • 8,077
  • 4
  • 21
  • 51
  • What is `startWith`? Are you referencing this answer, http://stackoverflow.com/a/834355/4333555? – chris85 Oct 18 '16 at 19:33
  • I was referring to the actual php startwith function but it appears that this post is about it yes. – Nicolas Oct 18 '16 at 19:35
  • There is no `startWith` PHP function, unless you define it.http://php.net/manual-lookup.php?pattern=startWith&scope=quickref `startwith doesn't exist.` If it did you'd probably pass `$value` to it, not concatenate it. – chris85 Oct 18 '16 at 19:35