Jump to content

[SOLVED] preg_replace - How to avoid/stop this.


Recommended Posts

So I am learning a bit of regex using preg, and I have this code I am trying to figure out how to parse more efficiently and for reasons I cannot find the definition to so I can fix it thus I am asking here.

 

<?php
$string = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="400" height="300"><param name="src" value="../bcms_uploads/myVideo.flv" /><param name="width" value="400" /><param name="height" value="300" /><embed type="application/x-shockwave-flash" src="../bcms_uploads/myVideo.flv" width="400" height="300"></embed></object>';

$html=preg_replace('~<object.*src="(.*)["](.*)</object>~','<a href="$1" style="display:block;width:400px;height:300px" id="player">df</a>',$string);
echo $html . " HTMLs";
?>

 

The printed code is:

<a href="../bcms_uploads/myVideo.flv" width="400" height="300" style="display:block;width:400px;height:300px" id="player">df</a> HTMLs

 

What it seems to be doing is finding the last " before it starts finding other stuff, I am not sure why it displays the width and height and not other information, but how do I get it to just stop after the first quote instead of finding some others first then stopping?

 

I hope what I said made sense and that it is not too hard of a question to answer. I know there are other ways to achieve the results, but I would just like to know why this is happening and if there is a way to do it with the above code.

 

Note:

width="400" height="300" 

 

Shouldn't be in the end result.

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.