Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Find and replace, extracting variables

    I currently have a script that inserts a video play on my blog, it looks for [video=11] 11 being the video id.

    I want to be able to have video variables, such as:

    [video=11&w=600&h=333]

    and then have each variable $filename, $width, $height.


    Any ideas?

    This is the code i am using.

    PHP Code:
    add_filter('the_content''ninexn_the_content');
    function 
    ninexn_the_content$content )
    {
        
    // find video id 
        
    $search "/\[video=(.*)\]/"
        
    preg_match_all($search$content$video_matches);
        
        if (
    is_array($video_matches[1]))
        {
            foreach (
    $video_matches[1] as $filename)
            {
                
    $search "[video=".$filename."]";
                
                
                
    $replace ninexnvideo($filename);
                
    $content str_replace ($search$replace$content);
                
            }
        }

        return 
    $content;


  • #2
    Regular Coder Iszak's Avatar
    Join Date
    Jun 2007
    Location
    Perth, Western Australia
    Posts
    332
    Thanks
    2
    Thanked 58 Times in 57 Posts
    I'm confused on what you want to do but here's something that'll allow the extra variables.

    PHP Code:
    <?php

    $string 
    '[video=11&w=600&h=333]';

    preg_match_all('#\[video=(\d+)&w=(\d+)&h=(\d+)\]#i'$string$matches);


    if (
    is_array($matches[1]) === true)
    {
      
    $i 0;
      foreach (
    $matches[1] as $filename)
      {
        
    $width  $matches[2][$i];
        
    $height $matches[3][$i];

        
    // Do whatever you need

        
    $i++;
      }
    }
    Last edited by Iszak; 03-17-2009 at 01:07 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
    •