preg_replace function to append a string to all the hyperlinks of a page

Posted by KoolKabin on Stack Overflow See other posts from Stack Overflow or by KoolKabin
Published on 2010-05-17T12:18:07Z Indexed on 2010/05/17 12:30 UTC
Read the original article Hit count: 263

Filed under:
|
|

hi guys,

i want to append my own value to all hyperlinks in a page... e.g if there are links:

<a href="abc.htm?val=1">abc 1</a> <br/>
<a href="abc.htm?val=2">abc 1</a> <br/>
<a href="abc.htm?val=3">abc 1</a> <br/>
<a href="abc.htm?val=4">abc 1</a> <br/>

I want to add next var like "type=int" to all hyperlinks

output should be:

<a href="abc.htm?val=1&type=int">abc 1</a> <br/>
<a href="abc.htm?val=2&type=int">abc 1</a> <br/>
<a href="abc.htm?val=3&type=int">abc 1</a> <br/>
<a href="abc.htm?val=4&type=int">abc 1</a> <br/>

I hope it can be done quite easily with preg_replace function

© Stack Overflow or respective owner

Related posts about php

Related posts about preg-replace