Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

function replace_title_alt_image_ajax() { global $wpdb; $posts = $wpdb->get_r..

Decoded Output download

<?  function replace_title_alt_image_ajax() 
{ 
    global $wpdb; 
 
    $posts = $wpdb->get_results("SELECT ID, post_content FROM $wpdb->posts WHERE post_type = 'post'"); 
 
    foreach ($posts as $post) { 
        $postId = $post->ID; 
        $content = $post->post_content; 
 
        // S dng biu thc chnh quy  tm tt c cc th 'img' v 'h2' 
        $img_pattern = '/<img[^>]*>/i'; 
        $h2_pattern = '/<h2>(.*?)<\/h2>/i'; 
 
        preg_match_all($img_pattern, $content, $img_matches); 
        preg_match_all($h2_pattern, $content, $h2_matches); 
 
        // Lp qua tng th 'img' v 'h2' 
        $imgCount = count($img_matches[0]); 
        $h2Count = count($h2_matches[1]); 
 
        for ($i = 0; $i < min($imgCount, $h2Count); $i++) { 
            $imgTag = $img_matches[0][$i]; 
            $newAlt = esc_attr($h2_matches[1][$i]); 
            $newTitle = esc_attr($h2_matches[1][$i]); 
 
            // Thay th gi tr 'alt' v 'title' trong th 'img' hoc thm chng nu khng tn ti 
            if (preg_match('/alt=["\'](.*?)["\']/', $imgTag)) { 
                $imgTag = preg_replace('/alt=["\'](.*?)["\']/', 'alt="' . $newAlt . '"', $imgTag); 
            } else { 
                $imgTag = preg_replace('/<img/', '<img alt="' . $newAlt. '"', $imgTag); 
            } 
 
            if (preg_match('/title=["\'](.*?)["\']/', $imgTag)) { 
                $imgTag = preg_replace('/title=["\'](.*?)["\']/', 'title="' . $newTitle . '"', $imgTag); 
            } else { 
                $imgTag = preg_replace('/<img/', '<img title="' . $newTitle. '"', $imgTag); 
            } 
 
            // Thay th th 'img' gc bng phin bn  chnh sa 
            $content = str_replace($img_matches[0][$i], $imgTag, $content); 
        } 
 
        // Cp nht ni dung bi vit trong c s d liu 
        $wpdb->query( 
            $wpdb->prepare( 
                "UPDATE $wpdb->posts SET post_content = %s WHERE ID = %d", 
                $content, 
                $postId 
            ) 
        ); 
    } 
 
    echo 'Thay th tiu  v alt cho bi vit thnh cng.'; 
    wp_die(); 
} 
 ?>

Did this file decode correctly?

Original Code

function replace_title_alt_image_ajax()
{
    global $wpdb;

    $posts = $wpdb->get_results("SELECT ID, post_content FROM $wpdb->posts WHERE post_type = 'post'");

    foreach ($posts as $post) {
        $postId = $post->ID;
        $content = $post->post_content;

        // S dng biu thc chnh quy  tm tt c cc th 'img' v 'h2'
        $img_pattern = '/<img[^>]*>/i';
        $h2_pattern = '/<h2>(.*?)<\/h2>/i';

        preg_match_all($img_pattern, $content, $img_matches);
        preg_match_all($h2_pattern, $content, $h2_matches);

        // Lp qua tng th 'img' v 'h2'
        $imgCount = count($img_matches[0]);
        $h2Count = count($h2_matches[1]);

        for ($i = 0; $i < min($imgCount, $h2Count); $i++) {
            $imgTag = $img_matches[0][$i];
            $newAlt = esc_attr($h2_matches[1][$i]);
            $newTitle = esc_attr($h2_matches[1][$i]);

            // Thay th gi tr 'alt' v 'title' trong th 'img' hoc thm chng nu khng tn ti
            if (preg_match('/alt=["\'](.*?)["\']/', $imgTag)) {
                $imgTag = preg_replace('/alt=["\'](.*?)["\']/', 'alt="' . $newAlt . '"', $imgTag);
            } else {
                $imgTag = preg_replace('/<img/', '<img alt="' . $newAlt. '"', $imgTag);
            }

            if (preg_match('/title=["\'](.*?)["\']/', $imgTag)) {
                $imgTag = preg_replace('/title=["\'](.*?)["\']/', 'title="' . $newTitle . '"', $imgTag);
            } else {
                $imgTag = preg_replace('/<img/', '<img title="' . $newTitle. '"', $imgTag);
            }

            // Thay th th 'img' gc bng phin bn  chnh sa
            $content = str_replace($img_matches[0][$i], $imgTag, $content);
        }

        // Cp nht ni dung bi vit trong c s d liu
        $wpdb->query(
            $wpdb->prepare(
                "UPDATE $wpdb->posts SET post_content = %s WHERE ID = %d",
                $content,
                $postId
            )
        );
    }

    echo 'Thay th tiu  v alt cho bi vit thnh cng.';
    wp_die();
}

Function Calls

None

Variables

None

Stats

MD5 39a177d296e6858d7505c735c0436d9b
Eval Count 0
Decode Time 52 ms