Jump to content

Extracting a changing url from a post and then replacing the same match later


Recommended Posts

Hello,  first post!  Please be gentle :)

 

I have lots and lots and lots of database entries, and i'm needing to extract some information, do some processing on it, then replace the original before resubmitting the post to the database...

 

An example of a field is:

<img src="http://xyz.badsite.com/random/letters/Image.jpg" /> 
Thanks.

 

I am wishing to extract this for initial processing:

http://xyz.badsite.com/random/letters/Image.jpg

 

After i've processed, i need to change:

xyz.badsite.com/img6/6678

to:

www.monkeygibbon.com

 

Then insert it back into the database.

 

Details:

  • http:// is a constant, its always plain http
  • xyz isn't garaunteed, it changes
  • badsite.com remains a constant
  • random/letters/ changes
  • Image changes
  • .jpg changes

 

Anyone able to help me out? :)

Here's another example but with html special characters too!!

[img:1pgprvhz]http&#58;//xyz&#46;badsite&#46;com/random/letters/Image&#46;jpg[/img:1pgprvhz]</center>

 

edit:

okay preg_replace_callback sounds like the way forward, use the callback method to do the processing and set my return as the replacement...

 

This works in "The Regex Coach" in so far that it selects an entry

http://(.*?)(.|&#46;)imageshack(.|&#46;)us/(([a-zA-Z0-9]*?)/){2}([a-zA-Z0-9]*?)(.|&#46;)(jpg|png|gif)

 

However it just plum won't work in PHP.  I first get a delimiter error, so i added @ at the beginning and end, then it gets no matches whilst the editor does:

@http://(.*?)(.|&#46;)imageshack(.|&#46;)us/(([a-zA-Z0-9]*?)/){2}([a-zA-Z0-9]*?)(.|&#46;)(jpg|png|gif)@

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.