Jump to content

jcurl - preg_match?


ExSpirit

Recommended Posts

I am having problems extracting some "code" with preg_match and I hope someone can help me how to extract the correct "code/word" from html code which looks like this:

 

My code: <b>ss.34-some<img src='http://mydomain.com/images/slash.gif'  alt='$'>anothernum.123.word</b>
My code: <b>other<img src='http://mydomain.com/images/slash.gif'  alt='$'>code.1234.test</b>
My code: <b>and.another<img src='http://mydomain.com/images/slash.gif'  alt='$'>code</b>
...

 

So from this HTML code I should get this:

 

ss.34-some$anothernum.123.word

other$code.1234.test

and.another$code

 

 

If anyone can help me I would really appreciate it.

Link to comment
https://forums.phpfreaks.com/topic/218030-jcurl-preg_match/
Share on other sites

<?php
$test = "My code: <b>ss.34-some<img src='http://mydomain.com/images/slash.gif'  alt='$'>anothernum.123.word</b>
My code: <b>other<img src='http://mydomain.com/images/slash.gif'  alt='$'>code.1234.test</b>
My code: <b>and.another<img src='http://mydomain.com/images/slash.gif'  alt='$'>code</b>
... ";
preg_match_all('/<b>[^<]*<img[^>]*alt=\'[^\']*\'[^>]*>[^<]+<\/b>/i', $test, $matches);
foreach ($matches[0] as $v){
        $out[] = preg_replace('/<b>([^<]*)<img[^>]*alt=\'([^\']*)\'[^>]*>([^<]+)<\/b>/i', '\1\2\3', $v);
}
print_r($out);
?>

Link to comment
https://forums.phpfreaks.com/topic/218030-jcurl-preg_match/#findComment-1131660
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.