scs3jb Posted July 1, 2008 Share Posted July 1, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/112839-extracting-a-changing-url-from-a-post-and-then-replacing-the-same-match-later/ Share on other sites More sharing options...
scs3jb Posted July 1, 2008 Author Share Posted July 1, 2008 Here's another example but with html special characters too!! [img:1pgprvhz]http://xyz.badsite.com/random/letters/Image.jpg[/img:1pgprvhz]</center> Quote Link to comment https://forums.phpfreaks.com/topic/112839-extracting-a-changing-url-from-a-post-and-then-replacing-the-same-match-later/#findComment-579564 Share on other sites More sharing options...
scs3jb Posted July 1, 2008 Author Share Posted July 1, 2008 Here's another example but with html special characters too!! [img:1pgprvhz]http://xyz.badsite.com/random/letters/Image.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://(.*?)(.|.)imageshack(.|.)us/(([a-zA-Z0-9]*?)/){2}([a-zA-Z0-9]*?)(.|.)(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://(.*?)(.|.)imageshack(.|.)us/(([a-zA-Z0-9]*?)/){2}([a-zA-Z0-9]*?)(.|.)(jpg|png|gif)@ Quote Link to comment https://forums.phpfreaks.com/topic/112839-extracting-a-changing-url-from-a-post-and-then-replacing-the-same-match-later/#findComment-579647 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.