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?

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.