eevan79 Posted July 4, 2010 Share Posted July 4, 2010 1). How to replace text with 3 tags: 1. [ img ] 2. images/smilies/smiley.gif 3. [ /img] with "smiley.gif" ? example: [img=http://...images/smilies/smiley.gif] -> smiley.gif 2). How to check if message contains only spaces? In script I allowed minmum 5 characters to post message. But when I press <space> 5 times I can post message. How to strip/wrap blank spaces? Quote Link to comment https://forums.phpfreaks.com/topic/206698-help-with-regex/ Share on other sites More sharing options...
wildteen88 Posted July 4, 2010 Share Posted July 4, 2010 1). How to replace text with 3 tags: 1. [ img ] 2. images/smilies/smiley.gif 3. [ /img] with "smiley.gif" ? example: [img=http://...images/smilies/smiley.gif] -> smiley.gif You'd use regex. Here is an example $str = '[img=http://...images/smilies/smiley.gif]'; $str = preg_replace('/\[img\](.*)\[\/img\]/i', '<img src="$1" />', $str); echo $str; How to strip/wrap blank spaces? Use trim Quote Link to comment https://forums.phpfreaks.com/topic/206698-help-with-regex/#findComment-1081027 Share on other sites More sharing options...
eevan79 Posted July 4, 2010 Author Share Posted July 4, 2010 Thanks. In fact, that's what I did, but I made a mistake. I just needed to put this code before I parse bbcode (html2bbcode). What about second question - how to remove spaces if there is more than 3 in row (example " ")? EDIT: for first question: Do I have to change all smilies, or can I get just filename and remove link and BBC tags? Example from and I want to get smiley.gif ... Quote Link to comment https://forums.phpfreaks.com/topic/206698-help-with-regex/#findComment-1081034 Share on other sites More sharing options...
ZachMEdwards Posted July 4, 2010 Share Posted July 4, 2010 function doublesapce($str) { while(strpos($str, ' ')) { $str = str_replace(' ', ' ', $str); } return $str; } Quote Link to comment https://forums.phpfreaks.com/topic/206698-help-with-regex/#findComment-1081058 Share on other sites More sharing options...
eevan79 Posted July 4, 2010 Author Share Posted July 4, 2010 Thanks for answer, but that doesnt solve problem. When I write 20 spaces and one character script counts 21 characters. If I write only spaces script doesnt allow to post less than 3 characters. So I can post if I type " 1 ", but not " ". Can I fix this with regex? Quote Link to comment https://forums.phpfreaks.com/topic/206698-help-with-regex/#findComment-1081093 Share on other sites More sharing options...
wildteen88 Posted July 5, 2010 Share Posted July 5, 2010 Reduce multiple spaces with regex $str = 'h e l l o !'; $new_str = preg_replace('/\s+/', ' ', $str); echo "<pre>$str\n". strlen($str) . "\n\n$new_str\n" . strlen($new_str) . "</pre>"; Quote Link to comment https://forums.phpfreaks.com/topic/206698-help-with-regex/#findComment-1081459 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.