![]() |
|
#1
|
|||
|
|||
str_replace and linksThis isnt a question for a change
but just a suggestion for beginners like me If you want a user to be able to personalise their input area the following are very useful. I wont explain them but the last one is ideal for activating links typed in by the user. PHP Code:
I have just thought of something, If anybody can make a suggestion on how to make the link open in a new page that would be great. Ignore the first line of this posting about there not being a question. |
|
#2
|
||||
|
||||
Processing BBCodes - using str_replace() / strtr()There's nothing wrong with your code so far, although my personal preference is NOT to use ereg_replace() anywhere in my codes - a much faster alternative is preg_replace().
Here are a few 'alternatives' to your existing codes above: PHP Code:
The cool thing about using an array is that you can add to this array during the time the script is run before finally converting all the bbcodes off a string / text. re: the link opening in a new window (using the code you supplied above): PHP Code:
__________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
|
#3
|
|||
|
|||
|
For some reason between now and yesterdays posting the activate link code doesnt seem to work
It seems to affect or be affected by other links below it. OK back to the drawing board I think I will start exploring preg_replace but any suggestions or articles welcome. ps JDS is using array a faster method or are there other benefits? |
|
#4
|
|||
|
|||
|
P.S. Before the code you've posted up "misunderstood" you should have called htmlspecialchars() on $description, to make any other HTML code in the post safe.
GF |
|
#5
|
||||
|
||||
|
Having your 'default' bbcodes in an array (or working with them through an array) means that you can store all these 'default', formatting-type, bbcodes in a flatfile or database. It just adds to the overall efficiency when you want to add, modify or delete... whenever.
Imagine adding a bbcode like [xxx] or [yyy] in the future! Having these replacements hard-coded in your scripts means you'd have to dig through the script or function at a later date and you certainly want to avoid that in the way that you code PHP scripts generally. Also, like I said in my previous post, you can add to this array on-the-fly, a good idea when you want to process or type bbcodes. Here's an example post where Allowee and I discuss adding the codes generally. For clarity, in that example, I used 2 arrays, one named '$replacements' and one named '$smilies'; they could have just as well been merged into one array named '$bbcodes'!... Incidentally, this is EXACTLY how I added the custom [html ], [css ] and [c++ ] bbcodes for these forums here. Finally, if it is not already obvious, working off an array like this means you only process ONE str_replace() statement to process ALL your bbcodes! __________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
Recent GIDBlog
Last Week of IA Training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The