Jump to content

$string = eregi_replace("\[", "<", $string); Outputs nothing


masteroleary

Recommended Posts

I get the same results when using your code. However, when using this code i get the results below.

function unfilter_Desc($string)
{
echo 'Input: '. $string . ' <br />String Test: ' . is_string($string) ."<br />";
$string = eregi_replace("\[", "<", $string);
echo 'Result: '. $string . '<br /><br /><br />';
}
unfilter_Desc('[b]hello[/b]');

 

Output

Input: [b]hello[/b]
String Test: 1
Result: 

Link to comment
Share on other sites

Here is another example which may work for you since my understanding that you are trying to input bbcodes..

I am still a noob when comes to regexp but trying to get few things sorted :)

 

	
function replace_tags($string) {

$RegExpPattern = array(
'/(&#33;|!){10,}/',
'/\[b\](.*?)\[\/b\]/is',
'/\[i\](.*?)\[\/i\]/is',
'/\[u\](.*?)\[\/u\]/is',
'/\\n/',
);

$RegExpReplace = array(
'!',
'<strong>\\1</strong>',
'<em>\\1</em>',
'<u>\\1</u>',
'<br />',
);

$string = preg_replace($RegExpPattern, $RegExpReplace, $string);

return $string;
}

Link to comment
Share on other sites

The problem with your original code is that you're only replacing "[" and not "]". As a result, the "<" does not find a closing ">", which mucks up your HTML. Change this line of code to see what I mean:

 

echo 'Result: '. htmlspecialchars($string) . '<br /><br /><br />';

Link to comment
Share on other sites

Here is another example which may work for you since my understanding that you are trying to input bbcodes..

I am still a noob when comes to regexp but trying to get few things sorted :)

 

	
function replace_tags($string) {

$RegExpPattern = array(
'/(&#33;|!){10,}/',
'/\[b\](.*?)\[\/b\]/is',
'/\[i\](.*?)\[\/i\]/is',
'/\[u\](.*?)\[\/u\]/is',
'/\\n/',
);

$RegExpReplace = array(
'!',
'<strong>\\1</strong>',
'<em>\\1</em>',
'<u>\\1</u>',
'<br />',
);

$string = preg_replace($RegExpPattern, $RegExpReplace, $string);

return $string;
}

I dont understand the code on the line with ################## below

$RegExpPattern = array(
'/(&#33;|!){10,}/',  // #######What is the purpose of the line?########
'/\[b\](.*?)\[\/b\]/is', 
'/\[i\](.*?)\[\/i\]/is', 
'/\[u\](.*?)\[\/u\]/is', 
'/\\n/', 
);

$RegExpReplace = array(
'!',
'<strong>\\1</strong>',
'<em>\\1</em>',
'<u>\\1</u>',
'<br />',
);

Link to comment
Share on other sites

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.