Results 1 to 7 of 7

Thread: Help with PHP - Strip variable

  1. #1
    New Pligger mateusmoraes's Avatar
    Joined
    Sep 2007
    Posts
    5

    Help with PHP - Strip variable

    Hi,

    I'm new to PHP (I'm migrating from ASP) and also to Pligg. I'm in need of a little help with something I believe it's not hard:

    How do I check if the $url variable has an specific value and then extract what doesn't match?

    Example: I have "http://youtube.com/watch?v=1234567" defined for $url. I want to strip just "http://youtube.com/watch?v=" so that the result is "1234567".

    I intend to use it in the link_summary.tpl file so I can get the thumbnails from Youtube videos in a dynamic way.

    Thanks in advance!

  2. #2
    Pligg Donor dollars5's Avatar
    Joined
    Dec 2006
    Posts
    1,960
    use preg_match - regular experssions are fast and efficient for pattern matching.

  3. #3
    New Pligger mateusmoraes's Avatar
    Joined
    Sep 2007
    Posts
    5
    Quote Originally Posted by dollars5 View Post
    use preg_match - regular experssions are fast and efficient for pattern matching.
    Thanks for replying.

    I actually thought of the following:

    Code:
    if(preg_match("'/http:\/\/www.youtube.com\/watch\?v=([0-9a-zA-Z\-\_]*)(.*)/i'", $this->url, $matches)) {
    			$this->youtube_id=trim($matches[1]);
    		}
    Problem is that I don't know if it's right not even where to add this piece of code. I tried in link_summary.tpl, inside {php}{/php} but it did not work.

  4. #4
    Pligg Donor dollars5's Avatar
    Joined
    Dec 2006
    Posts
    1,960
    You can refer to the example at embed_video module in your Pligg/modules folder/embed_videos/plugins/function.embedvideos.php - there they extract just the video code and use it - I think that will help you.

  5. #5
    Constant Pligger crakez's Avatar
    Joined
    Jul 2007
    Posts
    119
    I was also looking for a way to get thumbnails from Youtube videos in a dynamic way. Nice idea will try it.

  6. #6
    New Pligger mateusmoraes's Avatar
    Joined
    Sep 2007
    Posts
    5
    Quote Originally Posted by dollars5 View Post
    You can refer to the example at embed_video module in your Pligg/modules folder/embed_videos/plugins/function.embedvideos.php - there they extract just the video code and use it - I think that will help you.
    That helped a bit but I still don't know how to add this into link_summary.tpl

    Quote Originally Posted by crakez
    I was also looking for a way to get thumbnails from Youtube videos in a dynamic way. Nice idea will try it.
    That is actually easy. Once you get the Youtube Video ID you just have to insert it
    Code:
    <img src="http://img.youtube.com/vi/{$youtube_video_id}/2.jpg">

  7. #7
    New Pligger mateusmoraes's Avatar
    Joined
    Sep 2007
    Posts
    5
    OK, I should start with steps:

    1) how to assign a name to a variable?
    2) which file(s) should be used for that so I can retrieve this variable in link_summary.tpl?

Similar Threads

  1. Strip Tags Where Are They ?
    By itwasnotme in forum Questions & Comments
    Replies: 7
    Last Post: 06-21-2011, 11:50 PM
  2. how to remove html strip out tags from the files?
    By raghhav in forum Questions & Comments
    Replies: 2
    Last Post: 02-23-2010, 12:54 PM
  3. How to Strip HTML Attributes on Post Submit?
    By urc187 in forum Questions & Comments
    Replies: 4
    Last Post: 08-16-2009, 09:26 PM
  4. Replies: 6
    Last Post: 08-08-2007, 01:05 PM
  5. reading pligg "variable" into php code - variable assignment
    By aprathivadi in forum Questions & Comments
    Replies: 0
    Last Post: 06-05-2007, 01:18 AM

Posting Permissions

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