OK guys, this should tax the brain cells.. and its got me stumped. To be honest im probably trying to do the impossible! but im not gonna give up till ive heard it from one of you guys/women 🙂
the sting is as follows, this contains a bit more of the problem im trying to solve:
$string = "This text is going to be an entry on some sort of bulliten board thing and i want to make sure that <a href=http://www.link.com>links</a> and <b>bold text</b> are allowed, but not <font size=3 color=ff0000>stupid font sizes</font> and other silly html tags 🙂, after letting these tag's live i want it to replace www.link.com and ftp.link.com with fully fledged <a href> tags just incase someone is lazy, http://www.link.com and mailto:email@mail.com also need to be replaced with <a href> tags, and before you think its all over, i need the function to replace html specific characters with their &name; equivilents! (except of course the <a href>, <b> and <br> tags 😉 after all this has been done /n lines need to be replaced with <br> tags.."
now im not sure what order to do the above things in.. obviously they cant all be achieved with one parse of the string. For refrence ive split the main sections down:
- replace all instances of www.link.com, ftp.link.com or mailto:mail@mail.com to full a href tags, unless they already are in full <a href> tags.
- replace all instances of http://www.link.com, ftp://ftp.link.com with full a href tags, unless they already are in full <a href> tags.
- replace all /n lines with <br>
- parse the string and replace all html specific characters with their relevant &name; refrences, unless the character is part of an: <a href>, <b> or <br> tag.
now ive tried attacking, butchering and altering other code snippets, but to no avail.. im still stuck at the planning stage! heh. Any help would be excelent! 🙂
cheers,
Twigg