0

I studied following example


$copy_date = "Copyright 1999";
$copy_date = preg_replace("([0-9]+)", "2000", $copy_date);

 here any numeric will be replaced by 2000

But in following example I am confused !!

How to replace

width="anything" with value 280

Want to Substitute anything that appears after

   width=" 

with

   width="280"

example width="481" will be width="280"

Another example.....

 <iframe width="680" height="480" src="//www.youtube.com/embed/RTcgXcz-_G0" frameborder="0" allowfullscreen></iframe>

after preg_replace

should become

  <iframe width="280" height="200" src="//www.youtube.com/embed/RTcgXcz-_G0" frameborder="0" allowfullscreen></iframe>

1 Answer 1

1

use this:

$copy_date = '<iframe width="680" height="480" src="//www.youtube.com/embed/RTcgXcz-_G0" frameborder="0" allowfullscreen></iframe>' ;
$pattern = '/width="\d+"/i' ;
$new_style = 'width="280"' ;
$new_copy_date = preg_replace($pattern, $new_style, $copy_date) ;

echo $new_copy_date;
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.