I want to transform the following:
1. From:
<img class="lazyjs bbcodeImage" src="//google.com/blank.gif" data-original="http://google.com/poster.jpg" alt="image" />
1. To:
<img src="http://domain.com/poster.jpg" />
2. From:
<a rel="nofollow" href="/confirm/url/aHR0cDovL2dvb2dsZS5jb20%3D/" class="ajaxLink">
2. To:
<a href="http://google.com">
Basically, I want to use the data-original
for <img src
. The <a href
is first encoded with base64_encode
, then with urlencode
.
Here's what I've done at until now:
<?php
// 1
$string = '<img class="lazyjs bbcodeImage" src="//google.com/blank.gif" data-original="http://google.com/poster.jpg" alt="image" />';
echo preg_replace('/<img class="lazyjs bbcodeImage" src="\/\/google.com\/blank.gif" data-original="(.*?)" alt="image" \/>/', '<img src="$1" />', $string);
// 2
$string = '<a rel="nofollow" href="/confirm/url/aHR0cDovL2dvb2dsZS5jb20%3D/" class="ajaxLink">';
echo preg_replace('/<a rel="nofollow" href="\/confirm\/url\/(.*?)\/" class="ajaxLink">/', '<a href="$1">', $string);
?>
The problem is that on 2
I don't know how to decode the $1
.