Click here to Skip to main content
15,903,856 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,

I have some text: <iframe width="853" height="480" src="http://www.youtu....

I know how to replace width="857" to width="720", but my method is static(substr_replace($source, '720', 16, 3)).

If width="857" will have some other position in text, my method work horrible.

At php.net I found -

PHP
function array_replace_fun($a, $tofind, $toreplace) 
 { 
     $i = array_search($tofind, $a); 
     if ($i === false)
     { 
         return $a;
     } 
     else 
     { 
         $a[$i] = $toreplace; 
         return array_replace($a, $tofind, $toreplace);
     } 
 }


but function don't work.
Posted
Updated 10-Mar-12 5:49am
v2

1 solution

Use string functions not array functions.
Try $newstring = str_replace('857', '720', $source). This will do the replacement anywhere in the source string.

Hint for using PHP functions: be very careful about the order of arguments!

Peter
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900