0

Ive tried to get the Regex to work for this script.

What I need it to do is take the width and height from the youtube code that is inserted and replace it with a specified height and width.

$youtube = str_replace('width="' * ' "','width="500"' $_POST['youtube']);

Can anyone help with this?

2
  • 3
    1) show php code to display youtube, 2) show what have you tried Commented Mar 31, 2014 at 11:16
  • I did add code, the < ? php tags edited it out Commented Mar 31, 2014 at 11:19

1 Answer 1

3

Assuming your code is:

$code = 'width="100" and height="200"';

And then perform the below regex replace using preg_replace()

$code = preg_replace('/width="\d+"/', 'width="XXX"', $code);
$code = preg_replace('/height="\d+"/', 'height="XXX"', $code);

\d+ means any number of digit starting from length one.

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.