Jump to content

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.

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.