SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict itsource's Avatar
    Join Date
    Jun 2001
    Location
    Thailand
    Posts
    369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can Regular Expression help me?

    PHP Code:
    This article about php programming 
    [pic="1235.jpg"]
    [
    BoldHello world [/Bold]
    PHP is a server-sidecross-platformHTML embedded scripting language
    [pic="1236.gif"][pic="1237.gif"]
    ...... (and 
    more 
    I want to keep all image file name in array.
    Image file name in this script is 1235.jpg,1236.jpg,1237.jpg

    I don't know how to use regular expression to search picture filename and keep it in array. Any one can help me?
    I live in Thailand. My English grammar not well.

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Probably

    Code:
    $text = 'This article about php programming 
    [pic="1235.jpg"]
    [Bold] Hello world [/Bold]
    PHP is a server-side, cross-platform, HTML embedded scripting language
    [pic="1236.gif"][pic="1237.gif"]';
    
    //Using preg_match_all grab all the image tags and store image 
    //name part of it in the array $images[1]
    preg_match_all("/\[pic=\"([^\"]+)\"\]/", $text, $images);
    
    
    //Here is a sample of how to loop through and see that 
    //indeed the image names are in the array $images[1]
    foreach($images[1] as $key => $val) {
    	print $val."<br>";
    	}
    Last edited by freddydoesphp; Oct 2, 2001 at 14:56.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Freddy, write the code usign the CODE tag instead PHP tag, otherwise slashes will be omited (VB error?)

    Code by freddydoesphp
    Code:
    $text = 'This article about php programming 
    [pic="1235.jpg"]
    [Bold] Hello world [/Bold]
    PHP is a server-side, cross-platform, HTML embedded scripting language
    [pic="1236.gif"][pic="1237.gif"]';
    
    //Using preg_match_all grab all the image tags and store image 
    //name part of it in the array $images[1]
    preg_match_all("/\[pic=\"([^\"]+)\"\]/", $text, $images);
    
    
    //Here is a sample of how to loop through and see that 
    //indeed the image names are in the array $images[1]
    foreach($images[1] as $key => $val) {
    	print $val."<br>";
    	}

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahhh. yes thanks Paul, damn VB
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Addict itsource's Avatar
    Join Date
    Jun 2001
    Location
    Thailand
    Posts
    369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This code work when I'm assign $text=" some text";

    but don't work when value of $text come from textarea

    pleae look my code
    PHP Code:
    <?
        $text 
    htmlSpecialChars(stripslashes($HTTP_POST_VARS['content']));
        echo 
    $text."<hr>";
        
    //---- line 4
        
    preg_match_all("/\[pic=\"([^\"]+)\"\]/",$text$images);
        foreach(
    $images[1] as $key => $val) { print $val."<br>";}

    ?>
        <form  method="post" action="<? echo $PHP_SELF?>" >    
        <textarea name="content" cols="120" rows="15"><? 
                
    if (isset($HTTP_POST_VARS['content'])) echo htmlSpecialChars(stripslashes($HTTP_POST_VARS['content']));
                
    ?>
        </textarea><br>
        <input type="submit" name="Preview" value="Preview"><br><br>
        </form>
    if I type Computer Engineering book online [pic="pic_1004915243.jpg"] in textarea. It don't work (no picture keep in array) but if I uncomment line 4 and assign this code (not get from text area)
    PHP Code:
    $text ='Computer Engineering book online [pic="pic_1004915243.jpg"] '
    the array contain "pic_1004915243.jpg"

    What problem when get value from textarea? Why it doen't work? Thanks.
    I live in Thailand. My English grammar not well.


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
  •