Title: Decoding base64 endoded text
Last modified: December 16, 2020

---

# Decoding base64 endoded text

 *  Resolved [pgrafix](https://wordpress.org/support/users/pgrafix/)
 * (@pgrafix)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/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.
    -  This topic was modified 5 years, 7 months ago by [pgrafix](https://wordpress.org/support/users/pgrafix/).

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/decoding-base64-endoded-text/#post-13845862)
 * Hi [@pgrafix](https://wordpress.org/support/users/pgrafix/),
 * Here’s an example of how you might need to modify your function to make it work
   in the export:
 *     ```
       function convert_raw_html($content){
       	preg_match_all("/(?<=\[vc_raw_html]).*?(?=\[\/vc_raw_html])/", $content, $matches );
       	if ( ! empty( $matches ) ){
       		foreach ( $matches[0] as $match ) {
       			$rstr = base64_decode( $match );
       			$content = str_replace( $match[0], htmlentities( $rstr ), $content );
       		}
       	}
       	return $content;
       }
       ```
   
 * This assumes you’re passing the content element to the function during the export:
   [https://www.wpallimport.com/documentation/export/pass-data-through-php-functions/](https://www.wpallimport.com/documentation/export/pass-data-through-php-functions/).
 * Please keep in mind that this is only an example and it may need to be modified,
   which we won’t be able to help with. If you still have trouble, though, feel 
   free to follow up here and we’ll keep the thread open in case anyone else is 
   able to help.
    -  This reply was modified 5 years, 7 months ago by [WP All Import](https://wordpress.org/support/users/wpallimport/).
      Reason: Modified for export instead of import
 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/decoding-base64-endoded-text/#post-13966536)
 * Hi [@pgrafix](https://wordpress.org/support/users/pgrafix/),
 * I’m going to mark this as resolved since it’s been a while. Feel free to follow
   up in this thread if you still have questions.
 * Anyone else with questions, please open a new topic.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Decoding base64 endoded text’ is closed to new replies.

 * ![](https://ps.w.org/wp-all-export/assets/icon-256x256.png?rev=2570162)
 * [WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel](https://wordpress.org/plugins/wp-all-export/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-all-export/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-all-export/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-all-export/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-all-export/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-all-export/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * Last activity: [5 years, 6 months ago](https://wordpress.org/support/topic/decoding-base64-endoded-text/#post-13966536)
 * Status: resolved