Jump to content

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.

 

 

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.