I am trying to show image in my wordpress website which get from third-party. They give me raw data of image. For showimg image, I need to convert raw data(which get from third-party) to base64_encode. It was working perfectly but recently got an error with a specific image. For all other image is working perfectly.

I have debug and found the issue was create for base64_encode($file).

My Code :

$file = "image raw data which get form third-party";
$type = "image type"; // png, jpg, jpeg
$en_data = base64_encode($file);
<img src="data:image/<?=$type;?>;base64, <?= $en_data; ?> ">

Error :

Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, bool given in E:\xampp\htdocs\dev\wp-includes\formatting.php:3415 Stack trace: #0 E:\xampp\htdocs\dev\wp-includes\class-wp-hook.php(307): convert_smilies('\r\n<style type="...') #1 E:\xampp\htdocs\dev\wp-includes\plugin.php(191): WP_Hook->apply_filters('\r\n<style type="...', Array) #2 E:\xampp\htdocs\dev\wp-includes\post-template.php(253): apply_filters('the_content', '<!-- wp:shortco...') #3 E:\xampp\htdocs\dev\wp-content\plugins\my-plugin\pagetemplate\page_fullwidth-template.php(11): the_content() #4 E:\xampp\htdocs\dev\wp-includes\template-loader.php(106): include('E:\xampp\htdocs...') #5 E:\xampp\htdocs\dev\wp-blog-header.php(19): require_once('E:\xampp\htdocs...') #6 E:\xampp\htdocs\dev\index.php(17): require('E:\xampp\htdocs...') #7 {main} thrown in E:\xampp\htdocs\dev\wp-includes\formatting.php on line 3415

There has been a critical error on this website.

Thanks in advance

1 Answer 1


Here's the code from formatting.php

if ( get_option( 'use_smilies' ) && ! empty( $wp_smiliessearch ) ) {
    // HTML loop taken from texturize function, could possible be consolidated.
    $textarr = preg_split( '/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // Capture the tags as well as in between.
    $stop    = count( $textarr ); // Loop stuff.

The problem is preg_split is failing. Its documentation says it returns false on failure, but the code here isn't checking for that and feeding the result straight into count(). I'm not sure how to get more details of the preg_split failure. And arguably WordPress should cope with that and skip the smiley step here.

However I'd guess it's because your encoded image is huge and that's causing problems in general. Your simplest option is probably to disable convert_smilies(), either by clearing the use_smilies option or removing the filter

remove_filter( 'the_content', 'convert_smilies', 20 );

but I think your best bet would be to handle the image differently: ideally don't keep it in memory if it's large - stream it to disk and then fetch the image from an endpoint that reads that back in. However I appreciate that might get complicated quickly, depending on the page flow here: whether this page makes the web service call you're now trying to separate out into a separate request + so who owns the completion of that call, protecting / cleaning up the images downloaded, potentially sharing them between a cluster of WordPress servers (which might need a separate file share to keep these out of wp_uploads) etc.

  • Thanks @Rup :) It's work for me. Aug 30 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.