Bit of a different one here for you all; I want to go from HTML code to BBCode. Why you ask? I shall explain 🙂
I am co-creating a forum with a mate and would obviously like our members post using different font styles, add hyperlinks, etc. To insert them into a database, we used the following code:
Edit: It would appear that the forum doesn't like my code so here is the link to see it in a text file: http://www.2312.co.uk/code1.txt
With $message being the text that the user is posting. All displays correctly but the problem comes when you wish to edit the post. I need to convert all the HTML code back into HTML code for two reasons:
- So it's less confusing for my users
- So I can use the strip_tags() function to prevent any malicious code being used.
I've struggled for a good few hours with this code now and have got virtually nowhere. I have managed to convert the bold, italic and underline tags accordingly but am stuck after that.
Here is the code that I used to convert the bold, italic and underline tags back to HTML:
Edit: It would appear that the forum doesn't like my code so here is the link to see it in a text file: http://www.2312.co.uk/code2.txt
It would therefore seem logical to me that the following code would be correct for converting URLs:
Edit: It would appear that the forum doesn't like my code so here is the link to see it in a text file: http://www.2312.co.uk/code3.txt
But using that code gives the following error:
Warning: REG_BADRPT in /home/.sites/146/site439/web/hh/forum/edit.php on line 46
Line 46 is obviously the code that attempts to convert URLs.
Could you please offer me some pointers as to what I am doing wrong?
Thanks very muchly
Stu 🙂