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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Mar 2004
    Location
    Jackson, Georgia
    Posts
    102
    Thanks
    0
    Thanked 0 Times in 0 Posts

    getting file contents from within delimiters

    How would I go about getting file contents between delimiters?


    Example:

    $delimiter_number = "3";



    file "foo.txt" contains:

    fgfdgf
    gf

    gf
    gfgdsfgfdgdsfgfdgdsgfdgfd

    <!-- start$delimiter_number -->
    Random text
    <!-- end$delimiter_number -->

    fgfdgsfdg464




    How would I snag "Random text" from within the delimters?
    Designer's Toolz; Web & software development community.

    Get your coding questions answered:
    DTZ Forums

  • #2
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    are u trying to get it off from another page or the same page?

  • #3
    Regular Coder
    Join Date
    Mar 2004
    Location
    Jackson, Georgia
    Posts
    102
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I said its coming from a file.
    Designer's Toolz; Web & software development community.

    Get your coding questions answered:
    DTZ Forums

  • #4
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    maybe something like this base code by www.mikenew.net
    ---------------------------
    PHP Code:
    <?php
    $thefile 
    "FILENAME HERE";
    $fd fopen($thefile"r"); 
    $value "";
    while(!
    feof($fd)){
        
    $value .= fread($fd4096);    
    }
    fclose($fd);

    $startingpoint "<!-- start$delimiter_number -->"
    $endingpoint "<!-- end$delimiter_number -->";

    $value "";

    $startstrpos($value"$startingpoint");  
    $finishstrpos($value"$endingpoint");  
    $length$finish-$start;
    $value=substr($value$start$length);

    $echo preg_replace("/(href=\"?)(\/[^\"\/]+)/""\\1" $thefile "\\2"$value);
    echo 
    $echo
    flush ();
    ?>

  • #5
    Regular Coder
    Join Date
    Mar 2004
    Posts
    115
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php  
    $txt 
    file_get_contents('http://www.example.com/');
    $delimiter_number "3";
    $one=explode("<!-- start".$delimiter_number." -->",$txt);
    $two=explode("<!-- end".$delimiter_number." -->",$one[1]);
    $bit=$two[0];
    echo 
    $bit;
     
    ?>
    Last edited by sidney; 04-06-2004 at 02:40 PM.


  •  

    Posting Permissions

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