Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

many rows of html text, want a value from each line

text here<a href="/start.php?a=request-link&amp;s=new-york&amp;f=intake&amp;l=want-this-number"><img src="/images/start.gif" alt="Start"></a>more text here
text here<a href="/start.php?a=request-link&amp;s=new-york&amp;f=intake&amp;l=want-this-number"><img src="/images/start.gif" alt="Start"></a>more text here
text here<a href="/start.php?a=request-link&amp;s=new-york&amp;f=intake&amp;l=want-this-number"><img src="/images/start.gif" alt="Start"></a>more text here
text here<a href="/start.php?a=request-link&amp;s=new-york&amp;f=intake&amp;l=want-this-number"><img src="/images/start.gif" alt="Start"></a>more text here
text here<a href="/start.php?a=request-link&amp;s=new-york&amp;f=intake&amp;l=want-this-number"><img src="/images/start.gif" alt="Start"></a>more text here

many lines
please tell me how to get
want-this-number
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

For the exact text provided, this should work:
preg_match_all('#(?<=<a href="/start\.php\?a=request-link&amp;s=new-york&amp;f=intake&amp;l=)\d+#',$text,$matches);
print_r($matches);

Open in new window

You could also be more flexible in the URLs you accept, such as:

preg_match_all('#<a href="/start\.php[^"]*(?:\?|&amp;)l=(\d+)#',$text,$matches);
print_r($matches[1]);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America 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
Avatar of rgb192

ASKER

Terry's code
Array ( ) Array ( [0] => Array ( ) )


<?php

$text = <<<EOD
text here<a href="/start.php?a=request-link&amp;s=new-york&amp;f=intake&amp;l=want-this-number"><img src="/images/start.gif" alt="Start"></a>more text here
text here<a href="/start.php?a=request-link&amp;s=new-york&amp;f=intake&amp;l=want-this-number"><img src="/images/start.gif" alt="Start"></a>more text here
text here<a href="/start.php?a=request-link&amp;s=new-york&amp;f=intake&amp;l=want-this-number"><img src="/images/start.gif" alt="Start"></a>more text here
text here<a href="/start.php?a=request-link&amp;s=new-york&amp;f=intake&amp;l=want-this-number"><img src="/images/start.gif" alt="Start"></a>more text here
text here<a href="/start.php?a=request-link&amp;s=new-york&amp;f=intake&amp;l=want-this-number"><img src="/images/start.gif" alt="Start"></a>more text here
EOD;
  preg_match_all('#<a href="/start\.php[^"]*(?:\?|&amp;)l=(\d+)#',$text,$matches);
print_r($matches[1]);


preg_match_all('#(?<=<a href="/start\.php\?a=request-link&amp;s=new-york&amp;f=intake&amp;l=)\d+#',$text,$matches);
print_r($matches);

Open in new window

Avatar of rgb192

ASKER

Ray has the correct answer, not sure if Terry has correct answer

I opened another question asking why Ray's code works
https://www.experts-exchange.com/questions/28161784/first-part-of-parsing-many-lines.html
Avatar of rgb192

ASKER

did I implement Terry's code correctly?
Avatar of rgb192

ASKER

Ray had the only answer that I knew how to use.

Thanks