Re: I can't make 'read_tag.php' file
| From: | Bas | Date: | Mon, 13 Oct 2003 11:35:05 +0000 |
| Subject: | Re: I can't make 'read_tag.php' file | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-165954@lists.php.net to get a copy of this message | ||
This just says:
Parse error: parse error, unexpected T_STRING, expecting ')' in
C:\pub\read-tags.php on line 12
"Manuel VáZquez Acosta" <manu@chasqui.cu> wrote in message
news:20031012144044.3260.qmail@pb1.pair.com...
> Try this:
>
> function readTag($filenane, $tagtype, $degub = false)
> // I prefer boolean for debug :)
> {
> $filedata = file_get_contents($filename);
> $tagtype = preg_quote($tagtype);
> $tagRegExp = "/<battag=$tagtype\s*>((?:.|\s)*?)</battag\s*>/";
> preg_replace_callback($tagRegExp, 'replaceFunc', $filedata);
> }
>
> function replaceFunc(match)
> {
> // match[0] --- the whole tag from <x> to </x>
> // match[1] --- the contents of the tag
> // I am my self !!! in the example
>
>
> return WHATEVER_YOU_WANT_TO_REPLACE_THE_TAG;
> }
>
> I didnt make sure this script will work 100%; but it should.
>
> Manu.
>
> "Bas" <bas_timmer49@hotmail.com> wrote in message
> news:20031012095202.72855.qmail@pb1.pair.com...
> > I have found that this script doesn't work:
> >
> > read_tag.php
> >
> > ---
> > <?php
> >
> > function readTag($filename, $tagtype, $debug = 0) {
> > $filedata = file_get_contents($filename);
> > $tagrealname = "<bttag=";
> > $tagrealname .= $tagtype;
> > $tagrealname .= ">";
> >
> > $tagdata = stristr($filedata, $tagrealname);
> > $posofend = strpos($tagdata, "</bttag>");
> > $length = strlen($tagdata);
> > $lengthoftag = strlen($tagrealname);
> > $lengthofend = strlen("</bttag>");
> > $lengthofstr = $length - $posofend - $lengthoftag;
> > $returndata = substr($tagdata, $lengthoftag, $lengthofstr);
> > if ($debug == 1) {
> > echo "<br>Length = " . $length;
> > echo "<br>Of Tag = " . $lengthoftag;
> > echo "<br>Of Str = " . $lengthofstr;
> > echo "<br>Of End = " . $posofend;
> > echo "<br>TagData:<br>" . $tagdata;
> > }
> > return $returndata;
> > }
> > ?>
> >
> > <HTML>
> > <BODY>
> > <h1>Test readTag-functie</h1>
> > <?php echo readTag("test.tag", "bassie", 1); ?>
> > </body>
> > </html>
> >
> > ---
> > And with this, it needs the file 'test.tag'
> > ---
> > <bttag=bassie>
> > I am myself!!
> > </bttag>
> > <bttag=test>
> > This is a test!!!
> > </bttag>
> > <bttag=welcome>
> > Welcome!!!
> > </bttag>
> > <bttag=close>
> > Closing!!!
> > </bttag>
> > ---
> > The first parameter of the readTag function is the filename of the tag
> file.
> > The second is the tag to search for an the third is the debug mode.
> >
> > The error is that if i load this, the readTag function returns
everything
> > except for the Closing!!!
> >
> > What's wrong?
> >
> > I'm running Win XP with Apache 2.0.44(Win32) CGI setup and PHP 4.3.3