Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.