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
https://forums.phpfreaks.com/topic/36586-string-eregi_replace/#findComment-174371
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
https://forums.phpfreaks.com/topic/36586-string-eregi_replace/#findComment-174445
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
https://forums.phpfreaks.com/topic/36586-string-eregi_replace/#findComment-174642
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
https://forums.phpfreaks.com/topic/36586-string-eregi_replace/#findComment-175085
Share on other sites

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.