Decoding base64 endoded text
-
I am butting my head against the wall attempting to decode base64-encoded content at export or import. The site uses WP Bakery’s Virtual Composer as it’s page builder and it wraps encoded raw html between a shortcode designator: [vc_raw_html]base64-encoded html here[/vc_raw_html]. FYI, there other VC shotcodes in the content as well, but I am not having issues with modifying these via preg_replace.
Here is the function I wrote to a) match the text between the two “tags”; b) decode the matching string; and c) replace the encoded string with the decoded string:
$rhtml = preg_match("(?<=\[vc_raw_html]).*?(?=\[\/vc_raw_html])"); $rstr = base64_decode($rhtml); function convert_raw_html($ID){ if ( $content = get_post_field( 'post_content', $ID ) ) { $content = preg_replace($rhtml, $rstr, $content); return htmlentities( $content ); } }
The preg_match statement does select the encoded string between the tags according to testing on regex101.com against real data, but the code above totally deletes all content when trying to implement during an export (and import for that matter). I have also tested a variant where the preg_match and decode parameters are inline in the preg_replace.
If it were just a few records then I would handle this outside of the export/import process, but it is well over 200 records.
Any help would be greatly appreciated.
- The topic ‘Decoding base64 endoded text’ is closed to new replies.