Support

Account

Home Forums ACF PRO Need some regex help for oEmbed

Helping

Need some regex help for oEmbed

  • Hi,

    I’ve noticed certain embed providers like to enable a lot of extra parameters by default. I’ve manage to slim this down for Soundcloud for example, but can someone with some regex knowledge tell me if what I’m trying to do is possible? I have the following:

    $mediatype = get_sub_field('band_media_clip');
       if (strpos($mediatype, 'soundcloud') ) {
          $mediatype = preg_replace('/height="400"/', 'height="125"', $mediatype);
          $mediatype = preg_replace('/=true/', '=false', $mediatype);                             
          echo '<div class="embed-container">' . $mediatype . '</div>';

    }

    Is there any preg_replace that will capture both the height and the =true strings like I’ve shown and replace them in one expression, rather than me calling it twice?

  • Hi @bloodlvst

    No I don’t think so.. mainly because you’re not just removing them but you’re replacing them with new values. If the new values were the same (like “=false”) for both I guess it could be done but since you’re now actively choosing to replace exact strings with new values depending on what the string is this is the way to go.

    That said I’m not an expert in hardcore PHP. But from my experience this is fine!

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

You must be logged in to reply to this topic.