I was wondering how you would use preg_replace(), i know it can be used to search for and replace areas of text in a string. But i was wondering about the useage...
I found an example on php.net of the usage for it. I was wanting to use preg_replace() to strip out BB code that may come up in my SQL query. You can see what i mean by going here.
like if there is a string of text returned by my query that shows up on the page like this:
"This is a string of text with BB code included in it. The purpose of this part of the program is to remove bb code and replace it with xhtml formated url and img tags. For more information on XHTML go to [ URL =http://www.w3schools.com/] w3cschools.com [/ URL]."
(added additional spacing in bb code to cause it so show up
I'd like to make it to where it strips out the BB code, and replaces it with XHTML compliant code for links and images since it just doesnt look right.
so after preg_replace() got done it would look like this
< a href="http://www.w3schools.com/" target="_blank"> w3cschools.com < /a>
from what I gather from php.net, i need to assign a variable (an array) with strings to search for in the text, then another array with how to replace it. My question is, what is the exact syntax of doing this?