#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    113
    Rep Power
    10

    Regex


    i was never good with regex... could you please help me?

    1. Want to remove [stream ...] tags:
    $content = "blah blah blah [stream provider=video flv=x:video.flv embed=false share=false width=450 height=253 dock=true controlbar=over bandwidth=high autostart=false /]";

    $content = preg_replace( '/\[(stream provider)(.*)\/\]', '', $content);
    I know the regex is wrong...


    2. content= '[video title="vtitle" size=10 width=400 height=300]http://www.youtube.com/?v=xxx[/video]'

    how can i get this?
    $title=vtitle; size=10; width=400; height=300;
    $url=http://www.youtube.com/?v=xxx
    preg_match?

    note, tag may be only
    http://www.youtube.com/?v=xxx or
    [video title="vtitle" size=10]http://www.youtube.com/?v=xxx[/video]
    (users do not use always full options)


    Many, many... Thanks
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,066
    Rep Power
    9398
    Thread renamed; moved from PHP.

    1. You're missing the closing delimiter. But you also have another issue: * is greedy, so if there are two of those [stream] things then not only will they both disappear (as expected) but everything in between the first and last tag will disappear too. Adding a ? makes it ungreedy:
    Code:
    #\[stream.*?/\]#i
    Allows for an empty [stream] (even if that's invalid).


    2.
    Code:
    #\[video(\s+|title="([^"]+)"|size=(\d+)|width=(\d+)|height=(\d+))+\](.*?)\[/video\]#i
    Do a print_r on the matches you get back to see what went where. You can then assign the bits to individual variables.

IMN logo majestic logo threadwatch logo seochat tools logo