I have a function I use for str_replace some BB-codes and such: function bbcode_to_html() { global $tekst; $tekst = str_replace("[B]","<strong>",$tekst); $tekst = str_replace("[/B]","</strong>",$tekst); $tekst = str_replace("[I]","<em>",$tekst); $tekst = str_replace("[/I]","</em>",$tekst); $tekst = str_replace("[U]","<span class=\"underline\">",$tekst); $tekst = str_replace("[/U]","</span>",$tekst); $tekst = str_replace("[b]","<strong>",$tekst); $tekst = str_replace("[/b]","</strong>",$tekst); $tekst = str_replace("[i]","<em>",$tekst); $tekst = str_replace("[/i]","</em>",$tekst); $tekst = str_replace("[u]","<span class=\"underline\">",$tekst); $tekst = str_replace("[/u]","</span>",$tekst); $tekst = str_replace("[!]","<span class=\"important\">",$tekst); $tekst = str_replace("[/!]","</span>",$tekst); $tekst = str_replace("\r\n","<br />",$tekst); $tekst = str_replace("&","&",$tekst); $tekst = preg_replace('/\[url\=(.*?)\](.*?)\[\/url\]/is','<a href="\\1">\\2</a>',$tekst); } PHP: It works, but it's sort of... limited in the way it can be used. It involves me having the $tekst-variable present in the page, of course, and therefore it is sort of not useful if I have more than one variable I need to parse through the function. The function itself is stored in a global_variables.php-file. What I would like to be able to do, with this function, is to parse a variable to it, from the page, and then return that variable to the page using the function - although I'm a little unsure as to how to do this, and also, how to integrate this function into other functions in different files. Anyone have any tips, links etc?
You chould change it to function bbcode_to_html($tekst) { $tekst = str_replace("[b]","<strong>",$tekst); $tekst = str_replace("[/b]","</strong>",$tekst); $tekst = str_replace("[i]","<em>",$tekst); $tekst = str_replace("[/i]","</em>",$tekst); $tekst = str_replace("[u]","<span class=\"underline\">",$tekst); $tekst = str_replace("[/u]","</span>",$tekst); $tekst = str_replace("[b]","<strong>",$tekst); $tekst = str_replace("[/b]","</strong>",$tekst); $tekst = str_replace("[i]","<em>",$tekst); $tekst = str_replace("[/i]","</em>",$tekst); $tekst = str_replace("[u]","<span class=\"underline\">",$tekst); $tekst = str_replace("[/u]","</span>",$tekst); $tekst = str_replace("[!]","<span class=\"important\">",$tekst); $tekst = str_replace("[/!]","</span>",$tekst); $tekst = str_replace("\r\n","<br />",$tekst); $tekst = str_replace("&","&",$tekst); $tekst = preg_replace('/\[url\=(.*?)\](.*?)\[\/url\]/is','<a href="\\1">\\2</a>',$tekst); return $tekst; } PHP: so to use it you would just have to put something like $something_else = bbcode_to_html($something); PHP:
And that, for some reason, does not seem to work... NEVERMIND It works just fine - I'm just being extremely stupid sometimes (Left a variable that f*cked up everything, not at all weird I couldn't get it to work). Thanks again!