HTML replace

$stringA = "<input type=‘text’ class=‘text urlfield’ name=‘attachments[1004]’ value=‘http://www.domain.com/URL’ /><br /> <button type=‘button’ class=‘button urlnone’ title=‘’>None</button> <button type=‘button’ class=‘button urlfile’ title=’

http://www.domain.com/URLa

'>URL do ficheiro</button> <button type=‘button’ class=‘button urlpost’ title=‘http://www.domain.com/URLb’>URL do Post</button>";

$stringB = “<input type=‘text’ class=‘text urlfield’ readonly=‘readonly’ name=‘attachments[1004]’ value=‘http://www.domain.com/URL’ /><br />”;

How can I get http://www.domain.com/URLa from $stringA and change for the following?
note: http://www.domain.com/URLa is random, so it must be grabbed from $stringA … class=‘button urlfile’ title=‘http://www.domain.com/URLa

$stringA = "<input type=‘text’ class=‘text urlfield’ name=‘attachments[1004]’ value=’

http://www.domain.com/URLa

’ /><br /> <button type=‘button’ class=‘button urlnone’ title=‘’>None</button> <button type=‘button’ class=‘button urlfile’ title=’

http://www.domain.com/URLa

'>URL do ficheiro</button> <button type=‘button’ class=‘button urlpost’ title=‘http://www.domain.com/URLb’>URL do Post</button>";

$stingB = "<input type=‘text’ class=‘text urlfield’ readonly=‘readonly’ name=‘attachments[1004]’ value=’

http://www.domain.com/URLa

’ /><br />";

So in a given string, there are always 2 urls, and you want to take the first url and replace it with the second url.

Is that what you mean?