Jump to content

Recommended Posts

going literally by what you say, this will work

 

$string = "src=\"lalala.htm\"";

$string = str_replace("src=\"lalala.htm\"","src=\"http://funny.com/lalala.htm\"",$string);

 

of course, you probably meant that you want ANYTHING after src="...." to be converted into a proper link, and this would require REGEX, so you probably want to ask in the forum above called PHP Regex

Great, i have read how to post a question in Regex forum so :

 

What i want is to load the page from another directory than pages directory this needs the src's to be src="http://domain.com/page.htm" and not src="page.htm" .

I have a string with an html page in it and a string with the sites domain.

So i want to change every src into the page that it doesnt include domain with the http://domain+page.

Thank you

Try this...

 

<?php

$content = 'src="lalala.html" ..efwef943434knrg src="http://lelelele.html" werfer4m34/rg5tkrwe3 src="lululul.html"';
$domain = 'http://example.com/';

$content = preg_replace('/src="(?!http:\/\/)([^"]+)"/', 'src="' . $domain . '$1"', $content);

print $content;

?>

Just thought...

 

I don't know what you plan on doing when the path has a leading slash, but to prevent them from having two slashes when you add 'http://example.com/' to the front of it, change the regex slightly to: src="\/?(...) - if you get me?

MrAdam thank you, and thank you for the correction , now its perfect.

I always called regex as php magic, today i learned that is called regex!

I am very interesting to learn it and i am very curious of it.

It seems to me that is a program language inside php.

Do you have in mind any php book bible that has even regex in it?

Do you have in mind any php book bible that has even regex in it?

 

The book I always recommend with regards to learning regex is Mastering Regular Expressions.

 

Additional online resources include:

regular-expressions

weblogtoolscollection

php freaks regex tutorial

php freaks resources

 

More than enough to get you started ;)

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.