Don't do this in PHP. This is a design decision, so it should be done with CSS:
a {
text-transform: uppercase;
}
If you really have to do it in PHP, you can use preg_replace_callback(), which allows you to write your own function that handles the replacement. This could look like this:
<?php
$string = '<body>Hello World <a href=http://web.com title="link">This is a link</a>';
$string = preg_replace_callback("/(<a.+title=[\"'])(.+?)([\"']>)([^<>]+?)(<\/a>)/", "callback_strtolower", $string);
echo $string;
function callback_strtolower($matches) {
var_dump($matches);
return $matches[1] . strtoupper($matches[2]) . $matches[3] . strtoupper($matches[4]) . $matches[5];
}
?>
Result:
<body>Hello World <a href=http://web.com title="LINK">THIS IS A LINK</a>
Note that this regular expression doesn't match all possibilities on how to write the html tags, you will have to adapt it.
Also note that it is usually a bad idea to use regular expressions to modify or parse HTML code. The recommended way is to use a DOM parser:
$dom = new DOMDocument();
$dom->loadHTML($string);
$links = $dom->getElementsByTagName("a");
foreach ($links as $link) {
foreach ($link->childNodes as $child) {
if ($child instanceof DOMText)
$link->replaceChild(new DOMText(strtoupper($child->wholeText)), $child);
}
if ($link->hasAttribute("title")) {
$link->setAttribute("title", strtoupper($link->getAttribute("title")));
}
}
echo $dom->saveHTML();