0

I have this content in a variable named for example $iframe

$iframe='<iframe title="Example Iframe" width="640" height="360" src="https://example.com/mypage?parameter=1" frameborder="0" allowfullscreen></iframe>';

And I need to strip everything except the src URL without parameters

In the example above something like this should be the final result:

echo $iframe;

https://example.com/mypage

I'm not sure if there is a function to search for properties within a HTML string and then maybe use some regex to strip out the parameters...

1 Answer 1

1

Try regexp

/src=\"(.*?)(\?.*\"|\")/

example here. Working php example here

<?php

$re = '/src=\"(.*?)(\?.*\"|\")/';
$str = '\'<iframe title="Example Iframe" width="640" height="360" src="https://example.com/mypage?parameter=1" frameborder="0" allowfullscreen></iframe>\'';

preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);

// Print the entire match result
var_dump($matches[0][1]);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.