Created
March 5, 2025 04:41
-
-
Save quicksketch/c40197c6401701693da59d04c72760c2 to your computer and use it in GitHub Desktop.
preg_replace_all() example to replace Drupal 7 [scald] tags with Drupal 10 <drupal-media> tags
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
<?php | |
$input_lines = "My normal[scald=1:sdl_editor_representation][scald=2:sdl_editor_representation] | |
more texthere haha[scald=3:sql_editor_representation]this_does not work!"; | |
// Match all [scald] tags and pull out the IDs. | |
preg_match_all('/\[scald=(\d+).*?\]/u', $input_lines, $output_array); | |
$output_lines = $input_lines; | |
foreach ($output_array[0] as $index => $scald_tag) { | |
$scald_id = $output_array[0][$index]; | |
$uuid = $scald_id; // Convert Scald ID to media UUID here. | |
// Replace the [scald] tag with a <drupal-media> tag in the output. | |
str_replace($scald_tag, '<drupal-media data-entity-type="media" data-entity-uuid="' . $uuid . '"> </drupal-media>', $output_lines); | |
} | |
return $output_lines; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment