Results 1 to 5 of 5

Thread: (php) coder?

  1. #1

    (php) coder?

    Hi,
    I'm looking for a php (or other language) coder for a relatively easy job (in my unexperienced opinion).
    I have a text file (text.txt) which looks like this:
    _root.text=text goes here&end=1
    What I need is a php script that makes the "text goes here" appear, but not the "_root.text" or the "&end=1".
    I'm assuming php is the best way to go, but maybe I'm wrong... any alternative code is fine as long as it works on a regular server (ASP is NOT supported though).
    I'd of course be glad if anyone could provide help on this, but if this turns out to be harder than I thought, then I'd pay someone to do the job.
    Please contact me through email with free help or quote.
    [email protected] (remove the "NO-SPAM")
    Thank you.
    -laz.

  2. #2
    Join Date
    Jun 2001
    Posts
    929
    If this is what I think you are saying it should be simple, I can't think of the PHP code off hand but you want to just snip the first 11 characters from the start and the last 6 from the end?

  3. #3
    Join Date
    May 2002
    Location
    UK
    Posts
    1,616
    Right here goes.... (apologies if it needs a bit of tweaking, its pretty late and I've no time to test it )...

    Code:
    <?php
    
    // read the textfile into a variable called $content
    
    $filename="text.txt";
    $fp = fopen($filename, "r") or die("Error opening file");
    $content = fread($fp, filesize($filename));
    
    // grab the bit in between the first = and $
    
    preg_match("/=([\w\s]+)&/", $content, $bit_we_want);
    
    // then strip the = and & from each end and put it in $bit
    
    $bit = ereg_replace("(=|&)", "", $bit_we_want[0]);
    
    // do whatever you want with $bit here eg print it to screen
    
    echo $bit;
    
    ?>
    Hope this helps
    Clook Internet - www.clook.net
    Fully managed UK based webhosting provider
    Est 2002, 24/7 phone support, all the bells and whistles!

  4. #4
    Join Date
    May 2002
    Location
    Australia
    Posts
    18
    Lazarus
    If you've got only one line in your text.txt and text to extract doesn't have any "=" and "&" inside, you might get away with this:
    <?
    $fp = fopen("text.txt", "r") or die("Error opening file");
    $content = fread($fp, filesize("text.txt"));
    fclose($fp);
    $temp=explode("&",$content);
    $temp=explode("=",$temp[0]);
    echo $temp[0];
    ?>
    Your extracted text is in $temp[0].

    If you've got more than one line, theis code can be put in a loop.
    If it's always "_root.text=" and "&end=1", it's even easier:

    <?
    $fp = fopen("text.txt", "r") or die("Error opening file");
    $content = fread($fp, filesize("text.txt"));
    fclose($fp);
    $content=str_replace("_root.text=","",$content);
    $content=str_replace("&end=1","",$content);
    echo $content;
    ?>
    Your extracted text is in $content.
    Last edited by #fdd700; 06-24-2002 at 10:06 PM.

  5. #5
    Thanks a lot to both of you, your codes were very helpful.
    I used parts of it and parts of another one I got on another board, and finnaly got it to work. Not the most elegant way, I'm sure, but here's the code for anyone who's interested.
    Code:
    <?php
    
    // read the textfile into a variable called $content
    
    $filename="thecstext.txt";
    $fp = fopen($filename, "r") or die("Error opening file");
    $filecontent = fread($fp, filesize($filename));
    
    $string = ereg_replace( "_root.text=(.*)&", "\\1", $filecontent );
    $string = ereg_replace("&end=1","","$string");
    $string = ereg_replace("end=1","","$string");
    
    echo $string;
    
    ?>
    Thanks again.
    -Laz.
    loves WHT

Posting Permissions

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