mds1256 Posted December 28, 2010 Share Posted December 28, 2010 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? Quote Link to comment Share on other sites More sharing options...
Zurev Posted December 28, 2010 Share Posted December 28, 2010 I'm confused, you want a user to be able to choose the width and height of the embedded player? If so you can easily perform a preg_replace of height="xxx" with the users defined input, the same with the width. Quote Link to comment Share on other sites More sharing options...
Zurev Posted December 28, 2010 Share Posted December 28, 2010 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. Quote Link to comment Share on other sites More sharing options...
mds1256 Posted December 28, 2010 Author Share Posted December 28, 2010 do you have an example of the preg_replace method, as i've just tried this with no luck, cannot seem to get the syntax correct with the example you have provided? Thanks again Quote Link to comment Share on other sites More sharing options...
mds1256 Posted December 29, 2010 Author Share Posted December 29, 2010 all sorted using the example above. Thanks again! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.