Jump to content

preg_match_all and add slashes help


jmahdi

Recommended Posts

Hi there i have this code:

$str = "<i><font color="800080"> man </font></i><p><font color="9898989"> hi </font></p><p><font color="1111111"> cheers </font></p>";
$pattern = '/<font .*?>(.*?)<\/font>/';
if(preg_match_all($pattern, addslashes($str), $posts)){
        $i=0;
for($i; $i < count($posts[0]); $i++){
            echo "content: " . $posts[0][$i] . "<br/>";
            echo "colour: " . $posts[1][$i] . "<br/>";
             echo "<br />";
            
           }
}

 

and it doesn't work apparently because of the addslashes but its really needed as double quotes needs to be escaped, consider that i'm applying this code to a larger html file with hundreds of double quotes to be escaped....

 

error msg i get is Parse error: syntax error, unexpected T_LNUMBER in

thanks in advance..

Link to comment
https://forums.phpfreaks.com/topic/258452-preg_match_all-and-add-slashes-help/
Share on other sites

Your $str variable is not valid, you should be getting a parse error.

 

$str = "<i><font color="800080"> man </font></i><p><font color="9898989"> hi </font></p><p><font color="1111111"> cheers </font></p>";

 

Needs to be....

 

$str = "<i><font color=\"800080\"> man </font></i><p><font color=\"9898989\"> hi </font></p><p><font color=\"1111111\"> cheers </font></p>";

 

You don;t need addslashes at all.

I think i found the problem, i was using double quoutes in :

$str = "<i><font color="800080"> man </font></i><p><font color="9898989"> hi </font></p><p><font color="1111111"> cheers </font></p>";

 

while it should be:

$str = '<i><font color="800080"> man </font></i><p><font color="9898989"> hi </font></p><p><font color="1111111"> cheers </font></p>';

 

thanks anyways...:)

I think i found the problem, i was using double quoutes in :

$str = "<i><font color="800080"> man </font></i><p><font color="9898989"> hi </font></p><p><font color="1111111"> cheers </font></p>";

 

while it should be:

$str = '<i><font color="800080"> man </font></i><p><font color="9898989"> hi </font></p><p><font color="1111111"> cheers </font></p>';

 

thanks anyways...:)

 

that or what thorpe suggested.

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.