Results 1 to 12 of 12
  1. #1
    Join Date
    Mar 2004
    Posts
    74

    Unanswered: How do i replace string in this scenario ?

    Good day,

    When i using following query to pull out the data as following :-

    Code:
    SELECT url FROM mytable
    the url data will show following :-
    Code:
    <object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/RXbnq5eW0vo&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/RXbnq5eW0vo&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>
    but i would like to replace the width and height in specific value say width=200 , height=300 for both occurance, how can i do that ?

    meaning i would like to get the data after specific value replaced as show in following :-

    Code:
    <object width="200" height="300"><param name="movie" value="http://www.youtube.com/v/RXbnq5eW0vo&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/RXbnq5eW0vo&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="200" height="300"></embed></object>
    many thanks for guidance !

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    width and height appear twice, and you're wanting to change both...

    If you're going to be doing this often it may be advised to store it in the db with the format
    Code:
    <object width="[width]" height="[height]" ...
    Because this would make the replacements super easy
    George
    Home | Blog

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    better yet, store the url along with its attributes and construct the html from those values -- don't store the actual html itself
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Even better suggestion! ++1
    George
    Home | Blog

  5. #5
    Join Date
    Mar 2004
    Posts
    74
    Thanks all for reply,

    but the case here is the URL is user enter, in most case, the URL should take the width and height value from user , only in certain page, the movie need to display in specific size , any chance i can get it replace ?

  6. #6
    Join Date
    Mar 2004
    Posts
    74
    Hi George, i might be little dumb here, do you mind to explain further how your sample can be replace easily ?

  7. #7
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    yeah, george, go for it!

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  8. #8
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    It's called Replace()
    Code:
    SELECT Replace([field_name], '[string_to_find]', '[string_to_replace]');
    George
    Home | Blog

  9. #9
    Join Date
    Mar 2004
    Posts
    74
    Thanks George !

    what if the situation here insist me on just change the width and height ?

    what can i do for it ?

    Code:
    <object width="200" height="300"><param name="movie" value="http://www.youtube.com/v/RXbnq5eW0vo&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/RXbnq5eW0vo&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="200" height="300"></embed></object>

  10. #10
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    There's obviously a flaw, but here you go!
    Code:
    Replace(Replace(your_field_containing_the_url, '200', new_width_value), '300', new_height_value)
    George
    Home | Blog

  11. #11
    Join Date
    Mar 2004
    Posts
    74
    Thanks George !!!
    i forgot to mentioned the value of width and length is variable which depend on user define value actually

  12. #12
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Exactly! Which is why you need to reconsider the way in which you store the data.
    George
    Home | Blog

Posting Permissions

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