jmahdi Posted March 7, 2012 Share Posted March 7, 2012 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.. Quote Link to comment https://forums.phpfreaks.com/topic/258452-preg_match_all-and-add-slashes-help/ Share on other sites More sharing options...
trq Posted March 7, 2012 Share Posted March 7, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/258452-preg_match_all-and-add-slashes-help/#findComment-1324812 Share on other sites More sharing options...
jmahdi Posted March 7, 2012 Author Share Posted March 7, 2012 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... Quote Link to comment https://forums.phpfreaks.com/topic/258452-preg_match_all-and-add-slashes-help/#findComment-1324813 Share on other sites More sharing options...
AyKay47 Posted March 7, 2012 Share Posted March 7, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/258452-preg_match_all-and-add-slashes-help/#findComment-1324832 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.