I have my application to allow users to write comments on my website. Its working fine. I also have tool to insert their weblinks in it. I feel good with contents with their own weblinks.
Now i want to add rel=”nofollow” to every links on content that they have been written.
I would like to add rel=”nofollow” using php i.e while saving data.
So what’s a simple method to add rel=”nofollow” or updated rel=”someother” with rel=”someother nofollow” using php
a nice example will be much efficient
Regexs really aren’t the best tool for dealing with HTML, especially when PHP has a pretty good HTML parser built in.
This code will handle adding
nofollowif therelattribute is already populated.CodePad.
The resulting HTML is in
$dom->saveHTML(). Except it will wrap it withhtml,bodyelements, etc, so use this to extract just the HTML you entered…If you have >= PHP 5.3, replace
saveXML()withsaveHTML()and drop the second argument.Example
This HTML…
…is converted into…