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
If it’s a matter of just appending the variable to the
hrefattribute, then this would work:But if you are wanting code-hardiness, in that
href="index.php"gets changed intohref="index.php?type=int"and nothref="index.php&type=int", then you’ll need some extra checking: