OK, I have a section of code with things like:<a title="title" href="http://example.com">Text</a>
I need to reformat these somehow so that they become:<b>Text</b>
There are at least 24 links being changed, and they all have different titles and hrefs. Thanks in advance, Austin.
Although not optimal, you can do this with regular expressions:
$string = '<a title="title" href="http://example.com">Text</a>';
$string = preg_replace("/<a\s(.+?)>(.+?)<\/a>/is", "<b>$2</b>", $string);
echo($string);
This essentially says, look for a part of the string that has the form <a*>{TEXT}</a>
, copy the {TEXT}
, and replace that whole matched string with <b>{TEXT}</b>
.
Try this,
$link = '<a title="title" href="http://example.com">Text</a>';
echo $formatted = "<b>".strip_tags($link)."</b>";
Check this link out as well, I think this is what you are looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With