help...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

help...

Post 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
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Not sure what you're asking exactly?
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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?
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post 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.
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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?
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

Thanks, i'm goign to read over those and try some on my own!
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

str_replace is probably what you want. You can define $search and $replace arrays to deal with multiple BBcode tags.
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Take another look - that's what I use.
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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?
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Are you using array args?
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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...
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Code: Select all

<?php
$search = array('[ b]', '[ /b]', '[ i]', '[ /i]' ..etc);
$replace = array('<b>', '</b>', '<i>', '</i>' ..etc);
?>
Last edited by McGruff on Tue Aug 09, 2005 5:38 pm, edited 1 time in total.
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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!
Post Reply