Changing links in html

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nyk
Forum Newbie
Posts: 13
Joined: Mon Nov 22, 2004 8:07 pm
Location: Berne, Switzerland
Contact:

Changing links in html

Post by nyk »

Why won't this command

Code: Select all

$html=preg_replace('/http:\/\/subwww.unibe.ch\//','?c=',$html);
replace the URL with the ?c= ???
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

it looks like it should work to me, but maybe im missing it

still, you dont need regex for that, this is faster

Code: Select all

$html = str_replace('http://subwww.unibe.ch/', '?c=', $html);
nyk
Forum Newbie
Posts: 13
Joined: Mon Nov 22, 2004 8:07 pm
Location: Berne, Switzerland
Contact:

Post by nyk »

this doesn't replace anything. but the string to be replace occurs many times!

Code: Select all

$center=str_replace('href="http://subwww.unibe.ch/','href="?c=',$html);
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

if not, then you $html variable prob doesnt contain what you think, or your not using the result from str_replace correctly.

do this:

Code: Select all

echo $html;
echo "\n\n---------\n\n";
echo str_replace('http://subwww.unibe.ch/', '?c=', $html);
dont seperate those 3 lines and put other code in between, keep them together exactly as i posted them.

then just view the resulting source and your problem shoudl be obvious

if your still stumped, post the whole code here
Post Reply