0

here is my string

 $wpheader_output = "<!-- This site is optimized with the Yoast SEO plugin v11.0 - https://yoast.com/wordpress/plugins/seo/ -->
<meta name='msvalidate.01' content='C0C36649CDED53868CDF54EE8754432A' />
<meta name='google-site-verification' content='JhzC8-kGVNcajTnSfsFDtEbpnDt0FcTe6Y3I5z79Lig' />


<link rel='dns-prefetch' href='//s.w.org' />
<style id='yasrcss-inline-css' type='text/css'>

    .star-rating {
            background-image: url('https://www.example.com/wp-content/plugins/yet-another-stars-rating/img/star_oxy_0.svg');
        }
        .star-rating .star-value {
            background: url('https://www.example.com/wp-content/plugins/yet-another-stars-rating/img/star_oxy_1.svg') ;
        }

.star-rating .star-value {
                        -moz-transform: scaleX(-1);
                        -o-transform: scaleX(-1);

                        -webkit-transform: scaleX(-1);
                        transform: scaleX(-1);
                        filter: FlipH;
                        -ms-filter: 'FlipH';
                        right: 0;
                        left: auto;
                    }
</style>
<link rel='stylesheet' id='style-css'  href='https://www.example.com/wp-content/themes/newseo/style.css' type='text/css' media='all' />
<link rel='https://api.w.org/' href='https://www.example.com/wp-json/' />
<script type='text/javascript'>
  window._wp_rp_static_base_url = 'https://wprp.zemanta.com/static/';
  window._wp_rp_wp_ajax_url = 'https://www.example.com/wp-admin/admin-ajax.php';
  window._wp_rp_plugin_version = '3.6.4';
  window._wp_rp_post_id = '12000';
  window._wp_rp_num_rel_posts = '7';
  window._wp_rp_thumbnails = false;
  window._wp_rp_post_tags = [];
  window._wp_rp_promoted_content = true;
  window._wp_rp_admin_ajax_url = 'https://www.example.com/wp-admin/admin-ajax.php';
  window._wp_rp_plugin_static_base_url = 'https://www.example.com/wp-content/plugins/wordpress-23-related-posts-plugin/static/';
</script>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js'></script> " ;

i need to remove this line

<!-- This site is optimized with the Yoast SEO plugin v11.0 - https://yoast.com/wordpress/plugins/seo/ -->

i used to use perg_replace for that

$wpheader_output = preg_replace("/(<!-- This site is optimized with the Yoast SEO) (.|\n)*(plugins\/seo\/ -->)/", " ", $wpheader_output);

but after upgrading php version this wont work anymore so as suggested i tried preg_replace_callback

here is my code

 $wpheader_output = preg_replace_callback("/(<!-- This site is optimized with the Yoast SEO) (.|\n)*(plugins\/seo\/ -->)/" , function($matches) {
    return " ";
}, $wpheader_output);

but it will return null on this string

hretic
  • 999
  • 9
  • 36
  • 78
  • Try this: `'/\<\!--(.*)Yoast(.*)--\>/'`. That will match all `` that has the word `Yoast` in it, leaving other comments intact but will match changes to the comment in future versions (as long as they have Yoast in the comment). – M. Eriksson Apr 18 '19 at 14:36
  • Why wont that work, there's no `e` modifier usage.. What's your error? (Shouldnt use regex for HTML though) – user3783243 Apr 18 '19 at 14:36
  • 1
    Probably going beyond the backtracking limits? You have to give us a clue. The usage is correct and [regex matches the right chunk](https://regex101.com/r/hOCOsX/1). Try to replace `(.|n)*` with `[\s\S]*?`. BTW you don't need `preg_replace_callback` here. At all. – revo Apr 18 '19 at 14:37
  • @revo thanx changing the flag worked – hretic Apr 18 '19 at 14:44
  • Possible duplicate of [Why it's not possible to use regex to parse HTML/XML: a formal explanation in layman's terms](https://stackoverflow.com/questions/6751105/why-its-not-possible-to-use-regex-to-parse-html-xml-a-formal-explanation-in-la) – miken32 Apr 18 '19 at 15:51
  • Maybe they confused ereg, with preg... – ArtisticPhoenix Apr 18 '19 at 16:57

0 Answers0