I’m almost there!
Here is the string I am trying to adjust, and my preg_replace attempt.
$description_string = '<p>Here is the test link: <a href="http://www.youtube.com/watch?v=2MFn8L9tIrg" target="_blank">“Man or Muppet”</a> with other text afterwards.</p>';
$description = preg_replace( '/(<a[^>]+youtube[^>]*>)+[^"]*(<\/a>)+/', '$0Watch This Video$2', $description );
The result I’m getting is incorrect:
Here is the test link: “Man or Muppet”Watch This Video with other text afterwards.
Any help would be greatly appreciated! THanks!
Well, not sure if you are trying to get the actual title in there. But here is what I came up with:
Result:
Your biggest issue was with the quotes (“) being in the title. It is cutting off the anchor tags. While using $0 is also incorrect. You’ll need to use $1.
This may not be exactly what you need, but its a quick monkey patch for you.