Jump to content

Replace all between a string - maybe use wildcards??


mds1256

Recommended Posts

Hello

 

I have a form that takes an input, i want to replace 2 parts within the string see example

 

<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/fT7rCWZvsD8?fs=1&hl=en_GB"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/fT7rCWZvsD8?fs=1&hl=en_GB" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>

 

This is just an example but i want to replace all occurances of width="****" and height="***"

 

with

 

width="300"

height="198"

 

but the width and height are not always the same from the source so need a way to pickup - height="385"    then replace what ever is after that first speech mark and the last speech mark

 

Any ideas?

After reading this more carefully, I've realized a couple of things, if it is what I posted first you could do a preg_replace with a pattern of:

/width="\d{3}"/

 

However if you're looking to just replace what's between the object tags, you may be looking for something such as the following:

http://www.phpro.org/examples/Get-Text-Between-Tags.html

 

It would have to be modified slightly since you aren't just looking for things in between <object> and </object> but rather an object tag with attributes.

 

Hope this helped.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.