Link to home
Start Free TrialLog in
Avatar of okerupt
okerupt

asked on

PHP string from an array element

for ($i = 0; $i < count($lines); $i++)
{
if (strpos($lines[$i],"The river comes") >= 0)
{
      $current = $lines[$i];
}
}

This condition does show as true exactly once which is right.  $current, however,  is always just a return character.  I am getting so aggravated with this.
I have tried this using strval with the same result.
ASKER CERTIFIED SOLUTION
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just so you know, I tested it as follows:

$lines = array("When The river comes by",
               "blah",
               "The river comes through");
for ($i = 0; $i < count($lines); $i++) {
  print "Searching $i: ".$lines[$i]."<br>\n";
  if (is_numeric(strpos($lines[$i],"The river comes"))) {
    $current = $lines[$i];
    print "Found: $current at pos ".strpos($lines[$i],"The river comes")."<br>\n";
  }
}

displays:

Searching 0: When The river comes by
Found: When The river comes by at pos 5
Searching 1: blah
Searching 2: The river comes through
Found: The river comes through at pos 0
Avatar of okerupt
okerupt

ASKER

You're right about false = 0.  As a .net programmer that irritates me.