Page 1 of 1

help...

Posted: Mon Feb 16, 2004 7:40 pm
by Illusionist
I'm making a little forum/guestbook/message board thing, and was making my own little ocde, like BBcode and VBcode, but i've come across a problem. What i'm doing is just searching through the inputted text and replacing the tags, BUT i need a good way to continue to search through and find all the tags... anyone got any ideas?

Thanks

Posted: Mon Feb 16, 2004 7:44 pm
by McGruff
Not sure what you're asking exactly?

Posted: Mon Feb 16, 2004 7:56 pm
by Illusionist
lol, ya my question was sort of cryptic. The way im searching for the tags is jstu using strpos() and substr_replace() to change the tags accordingly. Problem is it only does one tag... i need a good way to keep looping through the text and change all the tags. i thought about jsut checking for "[" int he text, but the user might put a "[" in there and it would just loop over and over again. was tha any clearer?

Posted: Mon Feb 16, 2004 7:58 pm
by DuFF
If you are currently using preg_match try using preg_match_all
preg_match_all wrote:After the first match is found, the subsequent searches are continued on from end of the last match.
Edit
Ok, I guess you're not using preg_match. I would advise that you do, and use regular expressions to replace the code tags.

Posted: Mon Feb 16, 2004 8:11 pm
by Illusionist
ya i thought about using regular expressions, but i've enver sued them before so that'd be new to me. Does anyone know any good places to learn about regular expressions?

Posted: Mon Feb 16, 2004 8:54 pm
by DuFF

Posted: Mon Feb 16, 2004 9:29 pm
by Illusionist
Thanks, i'm goign to read over those and try some on my own!

Posted: Mon Feb 16, 2004 10:13 pm
by McGruff
str_replace is probably what you want. You can define $search and $replace arrays to deal with multiple BBcode tags.

Posted: Mon Feb 16, 2004 10:16 pm
by Illusionist
thank you McGruff, i'v also used that, and it still doesn't work like i need it too. It still only gets the first tags

Posted: Mon Feb 16, 2004 10:19 pm
by McGruff
Take another look - that's what I use.

Posted: Mon Feb 16, 2004 10:27 pm
by Illusionist
ok, i know how to get it to work, and yes it works fine when i use the same tag, but if i use two different tags it only does the first. I need a way of looping through the inputted text and find the tags. That was my original question, what is the best way of looping throught he text finding tags?

Posted: Mon Feb 16, 2004 10:37 pm
by McGruff
Are you using array args?

Posted: Mon Feb 16, 2004 10:40 pm
by Illusionist
no, all i'm doing is searching for a [ and then the ] and getting the tag in between then using a switch to determine what to replace...

Posted: Mon Feb 16, 2004 10:48 pm
by McGruff

Code: Select all

<?php
$search = array('[ b]', '[ /b]', '[ i]', '[ /i]' ..etc);
$replace = array('<b>', '</b>', '<i>', '</i>' ..etc);
?>

Posted: Mon Feb 16, 2004 11:01 pm
by Illusionist
:: BANGS HEAD AGAINST DESK :: So stupid!! why did i think of that!!!! lol, thansk so much! well, i jsut spent TOO long trying to do this the hardest way possible!!!!!!!! lol, thanks for saving me from using more worthless time!