Jump to content

Recommended Posts

Hi everyone

 

I have been trying for hours to understand a way to do this.

 

I need to replace all instances of "http" all the way to the first space character (get a url), as long as it does not end in ".jpg",".gif"...etc

 

I can match a URL,

/(http[^\s]+)/i

but cannot figure out a way to not match it if a picture extension is present in the end.

 

Thank you!

Link to comment
https://forums.phpfreaks.com/topic/191200-regular-expression/
Share on other sites

try this

$HTML = "test http:\\www.domain.comj\blar.html ing
http:\\www.domain.com\test\blar.jpg
http:\\www.domain.com\test\blar.html
http:\\www.domain.com\blar.html
http:\\www.domain.com\blar.gif
http:\\www.domain.com\blar.php
http:\\www.domain.com\blar.png
http:\\www.domain.com\blar.html
http:\\www.domain.com\blar.jpg";
$HTML = preg_replace('/\bhttp:\\\\\S+?\\\\[^.]*\.(jpg|png|gif)\S*\b/i', '', $HTML );
echo $HTML;

 

 

Link to comment
https://forums.phpfreaks.com/topic/191200-regular-expression/#findComment-1008145
Share on other sites

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.