demon_athens Posted March 8, 2006 Share Posted March 8, 2006 Hi there,I have a field of a mysql db with this kind of dataEXAMPLE[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<p>MPLA MPLA MPLA MPLA σαδηασηασδ ηασδ ηασδ ηασδη ασηασδηασδη ασδ ησαδη ασδησαδη ασδ ηασδ ηασδηασδ ηασδγη ασδηασδηασδη ασδ ηασδ ησαδηασηασδ ηασδ ηασδ ηασδη ασηασδηασδη ασδ ησαδη ασδησαδη ασδ ηασδ ηασδηασδ η</p><p align="center"><img width="1280" height="1024" src="/UserFiles/Image/AngelinaJolie77ee17_f1280.jpg" alt="" style="width: 498px; height: 395px;" /></p><p>ασδγη ηασδ ησαδηασηασδ ηασδ ηασδ ηασδη ασηασδηασδη ασδ ησαδη ασδησαδη ασδ ηασδ ηασδηασδ η</strong></p>[/quote]This field's data came from a webform with a wysiwyg editor fieldI want to replace the " /UserFiles " with an absolute url for example " [a href=\"http://localhost/UserFiles"\" target=\"_blank\"]http://localhost/UserFiles"[/a]How can I do it? I suppoce there is a string replacement function.The one that I found in php.net its not the thing i want. One way to do it is to do the replacement before inserting the data to the db. Can you help me with it? The basic problem is that I need all relative links to be absolute in this field..Thank you very much in advance Quote Link to comment Share on other sites More sharing options...
keeB Posted March 8, 2006 Share Posted March 8, 2006 I think what you might be looking for is a combination of the replace function you found on php.net .. and regular expressions, which are also available on php.net. I can help you further, but read up first and come back with more specific questions :) Quote Link to comment Share on other sites More sharing options...
demon_athens Posted March 8, 2006 Author Share Posted March 8, 2006 Lets make it specific then..." How can I find a string and replace it with another given string in a variable?"better? Quote Link to comment Share on other sites More sharing options...
keeB Posted March 8, 2006 Share Posted March 8, 2006 [!--quoteo(post=352988:date=Mar 8 2006, 09:06 PM:name=demon_athens)--][div class=\'quotetop\']QUOTE(demon_athens @ Mar 8 2006, 09:06 PM) [snapback]352988[/snapback][/div][div class=\'quotemain\'][!--quotec--]Lets make it spesific then..." How can I find a string and replace it with another given string in a variable?"better?[/quote]Ouch. Attitude.Well let me explain. Regular expressions can help you find the string ESPECIALLY IF IT IS DYNAMIC, I.E. you dont know what will be between [i]src="<here>"[/i]once you find that location OR the data reference [i]"<here>"[/i] you can easily replace the data with what you need it to be, and, using the same method, check to see IF it is already an absolute link.The reason I am not just giving you code is you can easily copy and paste it and not learn anything.. I am not trying to be a teacher, but what happens if you need this help again? That's why I gave you 2 topics to go read on.. Quote Link to comment Share on other sites More sharing options...
demon_athens Posted March 9, 2006 Author Share Posted March 9, 2006 As I allready said the code I am looking for is always starting with "/UserFiles/". So I know the string tha must be search and replaced.[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]The reason I am not just giving you code is you can easily copy and paste it and not learn anything.. I am not trying to be a teacher, but what happens if you need this help again? [/quote]Well, you are trying to be a teacher and I am not so stupid to come back with the same problem.Anyway my first though was to use Blow to blow the string and then remake it with the new absolute one( after each blow). The only reason I turned to this forum was because it seemed pretty much code ( and maybe heavy) for such an easy function.. So I asked and your answer was " Go and read mister!'Well, ok. Thanks ( this may explain my "attitude") Quote Link to comment Share on other sites More sharing options...
lessthanthree Posted March 9, 2006 Share Posted March 9, 2006 does$output = str_replace("/UserFiles", "http://localhost/UserFiles/", $string);not do the job? Quote Link to comment Share on other sites More sharing options...
demon_athens Posted March 9, 2006 Author Share Posted March 9, 2006 YESSSS!!! It's great. thank you very much for this line lessthanthree. Well it's pretty sure now that it was very easy and I didn't understood the examples of php.net.. ( this worries me a bit!)Thanks again! Have a nice day Quote Link to comment 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.