thePhpLady Posted February 24, 2012 Share Posted February 24, 2012 Hi there! I need to echo some text from a database table, this text should be linked to a url stored in the same database. I am trying to do this with preg_replace but I am terrible at it! I keep getting this error: Warning: Wrong parameter count for preg_replace() while($row = mysql_fetch_array( $result )) { $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; echo preg_replace ($reg_exUrl, $row['title'); Any suggestion? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/257714-help-with-preg_replace/ Share on other sites More sharing options...
premiso Posted February 24, 2012 Share Posted February 24, 2012 preg_replace You need the regex to find, the items to replace and the string where the replace occurs. Not really rocket science. Quote Link to comment https://forums.phpfreaks.com/topic/257714-help-with-preg_replace/#findComment-1320856 Share on other sites More sharing options...
thePhpLady Posted February 24, 2012 Author Share Posted February 24, 2012 I have changed the code, I understand the mistake. Now I can echo the text but it has no link. while($row = mysql_fetch_array( $result )) { $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; echo preg_replace ($reg_exUrl,$row['title'], $row['imageurl']); Quote Link to comment https://forums.phpfreaks.com/topic/257714-help-with-preg_replace/#findComment-1320860 Share on other sites More sharing options...
thePhpLady Posted February 24, 2012 Author Share Posted February 24, 2012 How can I show the text in 'title' with a link to 'imagurl'. Can I do that from the database? Quote Link to comment https://forums.phpfreaks.com/topic/257714-help-with-preg_replace/#findComment-1320864 Share on other sites More sharing options...
ManiacDan Posted February 24, 2012 Share Posted February 24, 2012 Show the contents of Title, Imgurl, and a final example of what you want. So far you're showing code that appears to want to take one URL out of title and replace it with another URL. Quote Link to comment https://forums.phpfreaks.com/topic/257714-help-with-preg_replace/#findComment-1320867 Share on other sites More sharing options...
thePhpLady Posted February 24, 2012 Author Share Posted February 24, 2012 the content of title is : Butterfly dress the content of imageurl is : http://www.styleandcurves.co.uk/sites/default/files/lb_dress.html Great Plains Butterfly Dress £10 What I want to do is click on Butterfly Dress and be redirected on b_dress.html. Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/257714-help-with-preg_replace/#findComment-1320871 Share on other sites More sharing options...
ManiacDan Posted February 24, 2012 Share Posted February 24, 2012 So what makes you think you need regex for this at all? echo '<a href="' . $row['imageurl'] . '">' . $row['title'] . '</a>'; Quote Link to comment https://forums.phpfreaks.com/topic/257714-help-with-preg_replace/#findComment-1320880 Share on other sites More sharing options...
thePhpLady Posted February 24, 2012 Author Share Posted February 24, 2012 Just to complicate my life! It works now, thank you. Quote Link to comment https://forums.phpfreaks.com/topic/257714-help-with-preg_replace/#findComment-1320896 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.