SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    38911 Basic Bytes Free johnuk's Avatar
    Join Date
    Jul 2008
    Location
    Somerset, England
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Find and replace values in string

    hey guys,

    This may seem like a no-brainier, but the thing is I wont know the length of the string in advance. My client has a pre-made/bought Blog which adds youtube videos into posts via its CMS - basically I want my function to search a string like the following:

    <embed width="425" height="344" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://www.youtube.com/somevid"></embed>

    and regardless of the current width and height values, I want to replace them with my own constants e.g width="325" height="244". Could someone kindly explain the best way to go about this?


    Many thanks in advance!!

  2. #2
    38911 Basic Bytes Free johnuk's Avatar
    Join Date
    Jul 2008
    Location
    Somerset, England
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I thought id found a solution but havent, so still open to any help

  3. #3
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,806
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    Try this:

    PHP Code:

    $original 
    =
    <
    embed width="425" height="344" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://www.youtube.com/somevid"></embed>

    $finish type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://www.youtube.com/somevid">

    $new = <embed width="12345" height="6789"

    $new $new $finish =
    <
    embed width="12345" height="6789" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://www.youtube.com/somevid"></embed
    # output:
    $original =
    <embed width="425" height="344" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://www.youtube.com/somevid"></embed>

    finish = type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://www.youtube.com/somevid">

    $new = <embed width="12345" height="6789"

    $new = $new . $finish =
    <embed width="12345" height="6789" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://www.youtube.com/somevid"></embed>
    The method is:
    1. get the basic string.
    2. save the last part of the string starting at "type=" to a new string $finish
    3. make a $new start string
    4. add the $new start string to the $finish string


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •