SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Jun 2008
    Posts
    205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    content written in file

    The below code works fine if i write the $text in the same file.

    Code:
    $text = '{AUTHOR}
    author1
    staff1
    {HEADLINE}
    DISPOSABLE DECOR: THE CUTTING EDGE DULLS FAST\
    STYLE AT A SPEED
    USUALLY ASSOCIATED WITH WARDROBE ITEMS.
    
    ';
    
    preg_match('~{AUTHOR}([^{]+)~is', $text, $matches);
    
    echo nl2br(trim($matches[1]));
    If I write the $text in a file called new.txt
    Code:
    {AUTHOR}
    author1
    staff1
    {HEADLINE}
    DISPOSABLE DECOR: THE CUTTING EDGE DULLS FAST\
    STYLE AT A SPEED
    USUALLY ASSOCIATED WITH WARDROBE ITEMS.
    {AUTHOR}
    author2
    staff2
    {HEADLINE}
    and the below code doesnot print the same value as above

    Code:
    <?php
    $fcontents = file ('new.txt');
    while (list($line,$str) = each( $fcontents ))  {
    preg_match('~{AUTHOR}([^{]+)~is', $str, $matches);
    echo nl2br(trim($matches[1]));
    }
    
    ?>
    It doesnot work and it doesnot print all the values between {AUTHOR} and first {}

  2. #2
    SitePoint Addict joaquin_win's Avatar
    Join Date
    Jul 2005
    Location
    Venezuela
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try using file_get_contents to get the whole content of the file and then do the replace like in the first example.


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
  •