Mutley Posted March 26, 2008 Share Posted March 26, 2008 I have an IPB forum, which when someone creates a smilie, it outputs this as the img src: "style_emoticons/<#EMO_DIR#>/wink.gif" The IPB software looks for this directory in the config but I'm writing a script to use it on a webpage. How can I make it so when I call this from the database in a script I am writing, it replaces <#EMO_DIR#> with something like 'smilies', so the image is then displayed correctly? Another example is when a user quotes someone. <!--quoteo(post=359329:date=Mar 26 2008, 05:52 PM:name=Mutley)--> How would I replace it with something simple like: <table class="quote"> I hope that makes sense, basically I want to replace certain strings from my database. Link to comment https://forums.phpfreaks.com/topic/98021-replacing-strings-of-text/ Share on other sites More sharing options...
Jeremysr Posted March 26, 2008 Share Posted March 26, 2008 For the first one you'd use str_replace: $string = "style_emoticons/<#EMO_DIR#>/wink.gif"; $string = str_replace('<#EMO_DIR#>', 'smilies', $string); And for the quote one you'd use preg_replace: $string = "<!--quoteo(post=359329:date=Mar 26 2008, 05:52 PM:name=Mutley)-->"; $string = preg_replace('/\<\!\-\-quoteo\(post\=([0-9]+)\:date\=([a-zA-Z0-9 ]+)\, ([0-9]+)\&\#58\;([0-9A-Z ]+)\:name\=(.+)\)\-\-\>/', '<table class="quote">'); I'm pretty sure that'll work. You can also display the post id, date, and username of the quote using preg_replace if you want. Link to comment https://forums.phpfreaks.com/topic/98021-replacing-strings-of-text/#findComment-501545 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.