I'm trying to make a BB Code script, setting the Bold, Italic, URL etc is easy enought but how do you make it scan for rogue links that aren't placed in a URL tag and same goes for email because I just can't get it to work.

Recommended Answers

All 6 Replies

htmlentities()

Hey rob! :) Can you explain to me how that's used please?

I'm not exactly sure of the PHP code to do this, but the algorithm might be for a string X, search the string until you detect "http://" ... from that on, it is a link until you reach whitespace. For each letter that isn't part of the URL, copy it directly into a new string X2. When you do detect a URL, add the appropriate code before and after it, and then copy it into X2. I think that might be a lot easier than inserting into the middle of the original string. I'm not sure how flexible php is with strings compared to C++ and Java, for example. Since it is a scripting language, however, I would assume it would natively be built to handle strings very well.

look at all the PHP functions avalable for doing something like this I have only found two that should work. They are preg_replace and eregi_replace but I only know the basics of how they work. for example

$text = preg_replace("#\[b\](.+?)\[/b\]#i","<b>\\1</b>",$text);

that would take what ever the value of text is and if it finds (in eather case) it will make the string that is inside bold.

I have looked at the PHP's preg syntaxs (sp) and I don't understand how they work well enough to know what to do.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.