masteroleary Posted February 1, 2007 Share Posted February 1, 2007 I am trying to replace the [ character with < by using the code: $string = eregi_replace("\[", "<", $string); But it outputs nothing. If I replace < with 0 then it works as should. Ideas? Quote Link to comment Share on other sites More sharing options...
effigy Posted February 1, 2007 Share Posted February 1, 2007 Works fine for me: <?php $string = '['; echo $string = eregi_replace("\[", "<", $string); ?> Quote Link to comment Share on other sites More sharing options...
masteroleary Posted February 1, 2007 Author Share Posted February 1, 2007 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: Quote Link to comment Share on other sites More sharing options...
Zeon Posted February 1, 2007 Share Posted February 1, 2007 Hi. Try this as a quick solution: function replace_tags($string){ $src = array('/\[/','/\]/'); $rep = array('<','>'); return preg_replace($src,$rep,$string); } echo replace_tags('[strong]Hello[/strong]'); Quote Link to comment Share on other sites More sharing options...
kucing Posted February 1, 2007 Share Posted February 1, 2007 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( '/(!|!){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; } Quote Link to comment Share on other sites More sharing options...
effigy Posted February 1, 2007 Share Posted February 1, 2007 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 />'; Quote Link to comment Share on other sites More sharing options...
masteroleary Posted February 1, 2007 Author Share Posted February 1, 2007 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( '/(!|!){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( '/(!|!){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 />', ); Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted February 3, 2007 Share Posted February 3, 2007 This line: '/(!|!){10,}/', Converts 10 or more explanation marks (!) into a single explanation mark. ! is the hex code for explanation mark. Quote Link to comment Share on other sites More sharing options...
mb81 Posted February 3, 2007 Share Posted February 3, 2007 This line: '/(!|!){10,}/', Converts 10 or more explanation marks (!) into a single explanation mark. ! is the hex code for explanation mark. It's an exclamation mark, not an explanation mark. Quote Link to comment Share on other sites More sharing options...
masteroleary Posted February 3, 2007 Author Share Posted February 3, 2007 Why would there be 10 ! marks ? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted February 4, 2007 Share Posted February 4, 2007 Not really sure on that one. You'll have to ask kucing that. I think kucing copied that from his BBCode parser. Its probably a way kucing uses to stop people "over-typing" exclamation marks (thanks mb891 for correcting me). Quote Link to comment 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.