mike1313 Posted December 31, 2007 Share Posted December 31, 2007 I want to be able to take a string and find out if they used a < b > tag. If that tag is used and the closing tag isn't </ b >. Then it adds it to the string. For ex. $string = "<b>Hi."; $add .="</b>"; $newstringafterwouldbe = "<b>Hi.</b>"; Just pointing me in the right direction on which function/s to use would be very helpful. Quote Link to comment https://forums.phpfreaks.com/topic/83780-find-tags-in-a-string/ Share on other sites More sharing options...
papaface Posted December 31, 2007 Share Posted December 31, 2007 What could it be instead of </b> ??? Quote Link to comment https://forums.phpfreaks.com/topic/83780-find-tags-in-a-string/#findComment-426284 Share on other sites More sharing options...
mike1313 Posted December 31, 2007 Author Share Posted December 31, 2007 No. The string will be users input and I'm allowing <B><U><I><S> only. What they post gets displayed on the page and I dont want them doing. <B><S>What's up? Without including the closing </B></S>, because in most cases it will mess things up. Quote Link to comment https://forums.phpfreaks.com/topic/83780-find-tags-in-a-string/#findComment-426293 Share on other sites More sharing options...
papaface Posted December 31, 2007 Share Posted December 31, 2007 How is the script supposed to know where to end the tags? Quote Link to comment https://forums.phpfreaks.com/topic/83780-find-tags-in-a-string/#findComment-426296 Share on other sites More sharing options...
mike1313 Posted December 31, 2007 Author Share Posted December 31, 2007 At the end of the string so $_POST[txt] = "<b>Hey"; $string = $_POST[txt]; if(condition == true){ $string .= "</b>"; } else { $string .= ""; } something along those lines Quote Link to comment https://forums.phpfreaks.com/topic/83780-find-tags-in-a-string/#findComment-426299 Share on other sites More sharing options...
raku Posted December 31, 2007 Share Posted December 31, 2007 You could look for the < /b>, then if it isn't found, add it on the end. if(strpos($string, "<b>") !== false && strpos($string, "</b>") !== false) { $string.="</b>"; } Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/83780-find-tags-in-a-string/#findComment-426321 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.