Jump to content

Where have I gone wrong here?


DamienRoche

Recommended Posts

All I want to do is find a match in a string - the whole string actually.

 

Here's my code:

 

<?php
$str = 'echo"<b>Hello the World!<\b>"';

if(!preg_match("#echo\"<\b>Hello the World!<\/\b>\"#", $str, $match))
{
echo "<br><b>Couldn't find:</b>".htmlentities($str)."<br>";
} else { 
echo "found match:".$match[0];}
?>

 

I have no idea where I am going wrong. I'm tried numerous reg ex combinations with escaping and also with the string - things like htmlentities() and stripslashes...I just don't know why I can't find a match.

 

Any help is greatly appreciated. Thanks.

Link to comment
https://forums.phpfreaks.com/topic/128148-where-have-i-gone-wrong-here/
Share on other sites

Here's my new code:

 

<?php
$str = 'echo"<b>Hello the World!<\b>"';

if(!preg_match("#echo\"<b>Hello the World!</\b>\"#", $str, $match))
{
echo "<br><b>Couldn't find:</b>".htmlentities($str)."<br>";
} else { 
echo "found match:".$match[0];}
?>

 

OUTPUT:

 

Couldn't find:echo"<b>Hello the World!<\b>"

 

I have no idea why it's doing this. I can match just text quite easily but as soon as I introduce the <b> tag, it crumbles.

 

Any other ideas? thanks.

 

 

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.