I have the following text found in my xml a couple of times:
Copyright © 2015.
I am trying to use regex to dynamically change the above text to always reflect the current year in the final release. This is my attempt and it does not work:
$finaloutput = preg_replace("/Copyright © [0-9]+/", "test", $finaloutput);
Of course, I use a hard-coded string ("test") only for testing purposes, because the current text already has 2015. So, my goal is to change this:
Copyright © 2015. All rights reserved ....
in it:
Copyright © test. All rights reserved....
Is my regex wrong?
PS: Just to give everyone a better understanding of the context, here (part) of the XML fragment $finaloutput is assigned:
<div class="dict_source"><strong>Powered by</strong> <a target="_blank" rel="nofollow" href="http://www.collinsdictionary.com/dictionary/english-spanish">Collins Complete Spanish Electronic Dictionary</a><br>Copyright © 2015 HarperCollins Publishers Limited.</div>
Update: I tried the answer suggested by @Avinash and still couldn't get it to work. To better illustrate the problem, I dug out the online tester preg_replace() . This is at https://www.functions-online.com/preg_replace.html . Here is the information that I entered in various input fields for testing:
$ pattern : '/(Copyright\s+©\s+)[0-9]+/u'
$ replacement : '\1test'
$ subject : <div class="dict_source"><strong>Powered by</strong> <a target="_blank" rel="nofollow" href="http://www.collinsdictionary.com/dictionary/english-spanish">Collins Complete Spanish Electronic Dictionary</a><br>Copyright © 2015 HarperCollins Publishers Limited.</div>
source share