Last active
March 9, 2020 16:12
-
-
Save edutrul/cc35c84255f189cd808eac3704919e1c to your computer and use it in GitHub Desktop.
Replace image src -- Drupal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$html = '<img src="/stories/archives/2020/january/images/example-an-image.jpg">'; | |
$html = html_entity_decode($html, ENT_QUOTES, 'UTF-8'); | |
$new_src = 'sites/{site_name}/files'; | |
$new_html = preg_replace('(src="(.*?)")','src="' . $new_src . '$1"', $html); | |
print $new_html; | |
// Outputs: "<img src="sites/{site_name}/files/stories/archives/2020/january/images/example-an-image.jpg">" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment