Jump to content

is this possible?


ted_chou12

Recommended Posts

<img src=\"/users/smilies/rolleyes.gif\" alt=\"Roll Eyes\">

<img src=\"/users/smilies/cheesy.gif\" alt=\"Cheesy\">

is it possible to add "http://domain.com" in front using preg_replace? so they become:

<img src=\"http://domain.com/users/smilies/rolleyes.gif\" alt=\"Roll Eyes\">

<img src=\"http://domain.com/users/smilies/cheesy.gif\" alt=\"Cheesy\">

Thanks.

Ted

Link to comment
Share on other sites

I've tried this:

$string = preg_replace("<img src=\"/users/smilies/(.+?)\.gif\" alt=\"(.+?)\">", "<img src=\"http://domain.com/users/smilies/\\1.gif\" alt=\"\\2\">", $entrycontent);
echo $string;

But it has extra <> in the out put, and when I added ` and `is at the front and the end, the output seems to be what I wanted (without <>), what do the ` and `is do?

Thank you for your help.

Ted

Link to comment
Share on other sites

This is very specific--it assumes that src is the first attribute in the image tag, and that double quotes are being used:

 

<?php
echo htmlentities(preg_replace('/(?<=<img src=")(?!http:)/', 'http://domain.com', '<img src="/users/smilies/rolleyes.gif" alt="Roll Eyes">'));
?>

Link to comment
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.