By netentropy on
I have just migrated someone's site to Drupal along with all images but I need to change the img src path and not the file name
basically
<img src="b.image.com/kittykat.png" />
needs to become
<img src="/images/kittykat.png" />
I am mostly having trouble with the preg replace pattern
Comments
What does your code look
What does your code look like?
Database dump and change
I have done this type of transition before by doing a database dump then a grep find/replace to catch all the possible iterations of the URL,
eg
This is a pretty drastic procedure but can work if you good with a text editor. In my case I did a bulk 30,000+ with a complex grep find/replace command and everything actually worked. Make sure you have everything backed up. Its also best to do on a development server first!!! You will like have to take a couple runs at it to work out all the possible problems
GOOD LUCK!
At the database level you can
At the database level you can also use the replace statement, something like
replacing table_name and field_name (twice) with the appropriate names.
This will generally be faster than dumping to a text file, changing and re-importing.
Good idea
You also need to be careful for other img src references. For example in my case we also had images in blocks and full URL's specified for theme settings (e.g. logos), not to mention images even in the header area of custom views. Basically all over the place. Dumping the Database was the easiest way to hit everything at once.
That said, nevets suggestion may work well if you are certain that you have a simple find/replace to do ONLY in your node bodies.
all the best
I have been trying to use
I have been trying to use form api and php to load each node body, search for all img tags, find and replace the source url before the last marker
can you use wildcards in the sql statement
the crappy thing is the last folder name changes before the file name.
Can you provide some actual
Can you provide some actual examples of what "last folder name changes before the file name" and what they need to map to?
@nevets Thanks with your help
@nevets
Thanks with your help on this.
basically I need everything before the last marker (/) to become /images/