php-general Digest 8 Nov 2007 10:43:22 -0000 Issue 5116

Topics (messages 264197 through 264217):

Re: Sessionvariable
        264197 by: Ronald Wiplinger

Help with preg_replace
        264198 by: Richard Luckhurst
        264199 by: Al
        264200 by: Jochem Maas
        264212 by: Robin Vickery

html parsing
        264201 by: Ron Croonenberg
        264203 by: Tom Ray [Lists]
        264204 by: Casey
        264205 by: Ron Croonenberg
        264206 by: Ron Croonenberg
        264208 by: Ron Croonenberg
        264209 by: Per Jessen
        264210 by: Jim Lucas
        264215 by: Ford, Mike

Re: help with link from mysql
        264202 by: Andrew Ballard

Re: gzuncompress() Not Working.
        264207 by: heavyccasey.gmail.com

Re: Benchmarking check to see if array key is set
        264211 by: Peter Ford

PHP ide?
        264213 by: Hulf
        264214 by: Shelley Shyan
        264216 by: Darryl Ware
        264217 by: Richard Heyes

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
Sebastian Hopfe wrote:
> Dear Ronald,
>
> I would like to ask you, want kind of session you use in you application.


I get information and put these information into a session variable,
like which language the page should be displayed. I have two frames on
that web page. One is the main page and one is a disclaimer. After a
while the disclaimer and then the main frame starts to fall back to the
default language.

I try from my desktop several browsers and so the information is in
different sessions almost the same.

I am doubting if the frames are the cause of vanishing SESSION information.

bye

Ronald
>
> regards
> Sebastian
>
> "Ronald Wiplinger" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
> news:[EMAIL PROTECTED]
>> I use at the first page a session variable to set a flag.
>>
>> After a few pages, or if somebody wait too long, the pages have another
>> flag.
>>
>> I noticed that there are often more than one session file exist.
>>
>> How can I avoid that?
>> How can I make sure that for one user is only one session file?
>>
>> bye
>>
>> Ronald 
>


-- 
Ronald Wiplinger  (CEO of ELMIT)
http://www.elmit.com  http://voip.elmit.com  http://ads.elmit.com 
Tel. (M) +886.939.775.516 (O) +886.2.2835.7765 (ENUM) 601*681 or FWD 511208
- I'm a SpamCon Foundation Member, #694, Verify it at http://www.spamcon.org

PS: Spam prevention!
Our system is protected with a spam prevention program. 
If you send us an e-mail, our system will send you a confirmation message back. 
Just reply to this confirmation message please. 
After receiving this confirmation message, our system will send the hold 
message (one) and all future messages (after the received confirmation message) 
to me without asking you again.

--- End Message ---
--- Begin Message ---
Hi 

I am in the process of porting a Perl application to PHP and I have hit a snag
with trying to substitute test within a file. I have looked at the PHP manual
and believe I should be using preg_replace but I have tried the examples and am
not getting the result I would expect. I would appreciate any help in getting
this to work.

In Perl I have the following

$html = `cat htmlfile`;
$html  =~ s/%ResID/$bookid/g;

which replaces each instance of %ResID with the contents of the variable $bookid

In PHP I have tried

$html = `cat htmlfile`;
$html = preg_replace('%ResID',$bookid,$html);

When I run this I find $html is empty rather than containing the file with the
%ResID replaced with the contents of $bookid.

I would appreciate any help with my understanding of preg_replace.



Regards,
Richard Luckhurst                      
Product Development
Exodus Systems - Sydney, Australia.
[EMAIL PROTECTED]
Tel: (+612) 4751-9633
Fax: (+612) 4751-9644
Web: www.resmaster.com 
=================================================
Exodus Systems - Smarter Systems, Better Business
=================================================

--- End Message ---
--- Begin Message --- Delimiters needed. Can use about anything not already in your pattern. "/" is very commonly used; but I like "#" or "%" generally; but, you can't use "%" because your pattern has it.

$html = preg_replace("#%ResID#",$bookid,$html);


Richard Luckhurst wrote:
Hi
I am in the process of porting a Perl application to PHP and I have hit a snag
with trying to substitute test within a file. I have looked at the PHP manual
and believe I should be using preg_replace but I have tried the examples and am
not getting the result I would expect. I would appreciate any help in getting
this to work.

In Perl I have the following

$html = `cat htmlfile`;
$html  =~ s/%ResID/$bookid/g;

which replaces each instance of %ResID with the contents of the variable $bookid

In PHP I have tried

$html = `cat htmlfile`;
$html = preg_replace('%ResID',$bookid,$html);

When I run this I find $html is empty rather than containing the file with the
%ResID replaced with the contents of $bookid.

I would appreciate any help with my understanding of preg_replace.



Regards,
Richard Luckhurst Product Development
Exodus Systems - Sydney, Australia.
[EMAIL PROTECTED]
Tel: (+612) 4751-9633
Fax: (+612) 4751-9644
Web: www.resmaster.com =================================================
Exodus Systems - Smarter Systems, Better Business
=================================================

--- End Message ---
--- Begin Message ---
Al wrote:
> Delimiters needed.  Can use about anything not already in your pattern.
> "/" is very commonly used; but I like "#"  or "%" generally; but, you
> can't use "%" because your pattern has it.
> 
> $html = preg_replace("#%ResID#",$bookid,$html);

wont a str_replace() do just fine in this case?

// and we can do backticks too ;-)
$html = str_replace("%ResID", $bookid, `cat htmlfile`);

> 
> 
> Richard Luckhurst wrote:
>> Hi
>> I am in the process of porting a Perl application to PHP and I have
>> hit a snag
>> with trying to substitute test within a file. I have looked at the PHP
>> manual
>> and believe I should be using preg_replace but I have tried the
>> examples and am
>> not getting the result I would expect. I would appreciate any help in
>> getting
>> this to work.
>>
>> In Perl I have the following
>>
>> $html = `cat htmlfile`;
>> $html  =~ s/%ResID/$bookid/g;
>>
>> which replaces each instance of %ResID with the contents of the
>> variable $bookid
>>
>> In PHP I have tried
>>
>> $html = `cat htmlfile`;
>> $html = preg_replace('%ResID',$bookid,$html);
>>
>> When I run this I find $html is empty rather than containing the file
>> with the
>> %ResID replaced with the contents of $bookid.
>>
>> I would appreciate any help with my understanding of preg_replace.
>>
>>
>>
>> Regards,
>> Richard Luckhurst                      Product Development
>> Exodus Systems - Sydney, Australia.
>> [EMAIL PROTECTED]
>> Tel: (+612) 4751-9633
>> Fax: (+612) 4751-9644
>> Web: www.resmaster.com =================================================
>> Exodus Systems - Smarter Systems, Better Business
>> =================================================
> 

--- End Message ---
--- Begin Message ---
On 08/11/2007, Jochem Maas <[EMAIL PROTECTED]> wrote:
> Al wrote:
> > Delimiters needed.  Can use about anything not already in your pattern.
> > "/" is very commonly used; but I like "#"  or "%" generally; but, you
> > can't use "%" because your pattern has it.
> >
> > $html = preg_replace("#%ResID#",$bookid,$html);
>
> wont a str_replace() do just fine in this case?
>
> // and we can do backticks too ;-)
> $html = str_replace("%ResID", $bookid, `cat htmlfile`);

As Jochem said.

But don't use backticks, use file_get_contents(). It's portable and
you don't start up a new process just to read a file.

$html = str_replace('%ResID', $bookid, file_get_contents('htmlfile'));

-robin

--- End Message ---
--- Begin Message ---
Hello,

I have a script that ads data to a html template.
However when there is an include in the html like:

<!--#include file="include/header.sinc" -->

it is not "processed", but "just" ends up as a string in the page.

So I guess it needs to be parsed. Is there an easy way to do that ?

thanks,

Ron

--- End Message ---
--- Begin Message ---
Ron Croonenberg wrote:
Hello,

I have a script that ads data to a html template.
However when there is an include in the html like:

<!--#include file="include/header.sinc" -->

it is not "processed", but "just" ends up as a string in the page.

So I guess it needs to be parsed. Is there an easy way to do that ?

thanks,

Ron

Do you have SSI enable in Apache? You are running Apache right? Do you have the file named .shtml? Or do you have Apache setup to run SSI through the HTML parser allowing you to have the files named .html instead. But I guess the other question is why are you using an SSI command that you could easily use a PHP command for and thus not have to mix the two?
--- End Message ---
--- Begin Message ---
Can you just change it to

<?php include('include/header.sinc); ?>

?


On Nov 7, 2007, at 7:24 PM, Ron Croonenberg <[EMAIL PROTECTED]> wrote:


Hello,

I have a script that ads data to a html template.
However when there is an include in the html like:

<!--#include file="include/header.sinc" -->

it is not "processed", but "just" ends up as a string in the page.

So I guess it needs to be parsed. Is there an easy way to do that ?

thanks,

Ron

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--- End Message ---
--- Begin Message ---
Yes I do have SSI enabled

here is what I am doing.

I have a php script that reads (a basic) file with html in it. (meaning
it it would have an html/shtml extension it would just work in a browser.

Now I rename the file to myhtml.dat and let the script read it and print
it to stdout.
That works like a char.....  until there's a server side include in the
html page. (ssi's work in both html and in php)

I tried to use  <?php include("that.file"); ?>  but that doesn't seem to
work



Tom Ray [Lists] wrote:
> Ron Croonenberg wrote:
>> Hello,
>>
>> I have a script that ads data to a html template.
>> However when there is an include in the html like:
>>
>> <!--#include file="include/header.sinc" -->
>>
>> it is not "processed", but "just" ends up as a string in the page.
>>
>> So I guess it needs to be parsed. Is there an easy way to do that ?
>>
>> thanks,
>>
>> Ron
>>
>>   
> Do you have SSI enable in Apache? You are running Apache right? Do you
> have the file named .shtml? Or do you have Apache setup to run SSI
> through the HTML parser allowing you to have the files named .html
> instead. But I guess the other question is why are you using an SSI
> command that you could easily use a PHP command for and thus not have to
> mix the two?
> 

-- 
=================================================================
 Ron Croonenberg                   |
                                   | Phone: 1 765 658 4761
 Lab Instructor &                  | Fax:   1 765 658 4732
         Technology Coordinator    |
                                   |
 Department of Computer Science    | e-mail: [EMAIL PROTECTED]
 DePauw University                 |
 275 Julian Science & Math Center  |
 602 South College Ave.            |
 Greencastle, IN  46135            |
=================================================================

--- End Message ---
--- Begin Message ---
I think the problem is that I read the lines in PHP, I read them with
fgets and output them with printf.

So the php "interpreter" never gets to see the line.

the apache doesn't parse php output, so it doesn't happen there either.

So..  I figured..  I either had to parse it in php myself OR convince
the apache server to parse it for me.

Ron

Casey wrote:
> Can you just change it to
> 
> <?php include('include/header.sinc); ?>
> 
> ?
> 
> 
> On Nov 7, 2007, at 7:24 PM, Ron Croonenberg <[EMAIL PROTECTED]> wrote:
> 
>>
>> Hello,
>>
>> I have a script that ads data to a html template.
>> However when there is an include in the html like:
>>
>> <!--#include file="include/header.sinc" -->
>>
>> it is not "processed", but "just" ends up as a string in the page.
>>
>> So I guess it needs to be parsed. Is there an easy way to do that ?
>>
>> thanks,
>>
>> Ron
>>
>> -- 
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
> 

-- 
=================================================================
 Ron Croonenberg                   |
                                   | Phone: 1 765 658 4761
 Lab Instructor &                  | Fax:   1 765 658 4732
         Technology Coordinator    |
                                   |
 Department of Computer Science    | e-mail: [EMAIL PROTECTED]
 DePauw University                 |
 275 Julian Science & Math Center  |
 602 South College Ave.            |
 Greencastle, IN  46135            |
=================================================================

--- End Message ---
--- Begin Message ---
ok I wrote something "quick and dirty" real quick:

But somehow it doesn't seem to like recursion. Is there something
"special" one needs to do in php ?

here's the code snippet:

function parsehtmlline($line)
{
if (strlen(strstr($line, "#include")) == 0 &&
    strlen(strstr($line, "<!--")) == 0) {
      /* nothing to parse just print it */
      print($line);
   }
else {
   /* extract the filename */
   $ssi = extractHTMLssi($line);

   /* open the file if it exists and output */
   /* it else just print the string         */
   if (file_exists($ssi)) {
      $incfile = fopen($ssi, "r");
      while (!feof($incfile)) {
         $ssiline = fgets($incfile, 1024);
// somehow PhP doesn't really like recursion, needs to be fixed
// for now just print the line.
//         parsehtmlline($ssiline);
         print($ssiline);
         }
      fclose($incfile);
      }
   else
      print($ssi);
   }
}

function extractHTMLssi($line)
{
$ssi = "";
$strptr = strstr($line, "\"");
if (strlen($strptr) == 0)
   return $line;
else
   {
   $ssi=$strptr;
   $iss=strrev($ssi);
   $strptr = strstr($iss, "\"");
   $iss = substr($strptr, 1, -1);
   $ssi = strrev($iss);
   }

return $ssi;
}

--- End Message ---
--- Begin Message ---
Ron Croonenberg wrote:

> I think the problem is that I read the lines in PHP, I read them with
> fgets and output them with printf.
> 
> So the php "interpreter" never gets to see the line.
> 
> the apache doesn't parse php output, so it doesn't happen there
> either.
> 
> So..  I figured..  I either had to parse it in php myself OR convince
> the apache server to parse it for me.

Absolutely.  Why are you parsing it yourself anyway - what value are you
adding? 


/Per Jessen, Zürich

--- End Message ---
--- Begin Message ---
Ron Croonenberg wrote:
I think the problem is that I read the lines in PHP, I read them with
fgets and output them with printf.

So the php "interpreter" never gets to see the line.

the apache doesn't parse php output, so it doesn't happen there either.

So..  I figured..  I either had to parse it in php myself OR convince
the apache server to parse it for me.

This is exactly where the problem lies. Apache isn't serving the page to PHP. PHP is just reading the file from the filesystem. What you might try is having PHP fopen() the url to the server/file. This way, apache will parse the SSI and spit out what it needs, then you can read the file anyway you like.

understand that php reading a file from the file system, is different then your browser calling to a server/webpage and having Apache serve the page back to the browser.


--
Jim Lucas


    "Perseverance is not a long race;
        it is many short races one after the other"

Walter Elliot



    "Some men are born to greatness, some achieve greatness,
        and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare

--- End Message ---
--- Begin Message ---
On 08 November 2007 06:41, Ron Croonenberg wrote:

> ok I wrote something "quick and dirty" real quick:
> 
> But somehow it doesn't seem to like recursion. Is there something
> "special" one needs to do in php ?

Recursive functions work just fine in PHP. What's the error message?

As far as I can see, there's nothing wrong with what you've posted, except for 
where there's some inefficiency due to not having found the right functions to 
use (see corrections below).

> 
> here's the code snippet:
> 
> function parsehtmlline($line)
> {
> if (strlen(strstr($line, "#include")) == 0 &&
>     strlen(strstr($line, "<!--")) == 0) {

  if (strpos($line, "#include")===FALSE && strpos($line, "<!--")===FALSE)

>       /* nothing to parse just print it */
>       print($line);
>    }
> else {
>    /* extract the filename */
>    $ssi = extractHTMLssi($line);
> 
>    /* open the file if it exists and output */
>    /* it else just print the string         */
>    if (file_exists($ssi)) {
>       $incfile = fopen($ssi, "r");
>       while (!feof($incfile)) {
>          $ssiline = fgets($incfile, 1024);
> // somehow PhP doesn't really like recursion, needs to be fixed
> // for now just print the line.
> //         parsehtmlline($ssiline);
>          print($ssiline);
>          }
>       fclose($incfile);
>       }
>    else
>       print($ssi);
>    }
> }
> 
> function extractHTMLssi($line)
> {
> $ssi = "";
> $strptr = strstr($line, "\"");
> if (strlen($strptr) == 0)
>    return $line;
> else
>    {
>    $ssi=$strptr;
>    $iss=strrev($ssi);
>    $strptr = strstr($iss, "\"");
>    $iss = substr($strptr, 1, -1);
>    $ssi = strrev($iss);
>    }
>
> return $ssi;

I'd replace the whole of this function body with something like:

  $pos = strpos($line, '"');
  if ($strpos===FALSE):
    return $line;
  else:
    return substr($line, $pos+1, strrpos($line, '"')-1);
  endif;


> }

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford,  Electronic Information Services Adviser,
JG125, The Headingley Library,
James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 812 4730          Fax:  +44 113 812 3211 


To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

--- End Message ---
--- Begin Message ---
On Nov 7, 2007 5:22 PM, Joey <[EMAIL PROTECTED]> wrote:
> I have a situation where I am storing data to a blob field. Everything works
> in respect to in and out of the DB, however when we type in a link like so
>
> HYPERLINK
> "http://www.abc.com/subfolder/folder2/"http://www.abc.com/subfolder/folder2/
>
>
> the link stops at the domain, so the subfolder/folder2 is merely text at the
> end of the url, and not part of the link.
>
>
> When I write the data to the table I do this:
>
> $body = addslashes($HTTP_POST_VARS['body']);
>
>
> When I read the data from the table I am doing this:
>
> 'body'                  => stripslashes(nl2br(makeLinks($row['body']))),
>
>
> Can someone let me know what I'm doing wrong, or how to work around this?

It's hard to tell very precisely just from what you've said, but here
are some general things you can check.

1) If magic_quotes are on for your server, the value you read from the
POST will already be escaped so using addslashes() would be redundant.

2) In any event, you'll find plenty of posts around here explaining
why you should use mysql_escape_string() instead of addslashes().
Note, if #1 above is a problem, you will want to unescape the string
with stripslashes() before you pass it into mysql_escape_string().

3) It's quite possible your makeLinks() function is not quite right.
I've found that given the allowable characters in a complete URL it
can be pretty challenging to get a function to find and convert all
the URLs in a string without converting too many or too few. Your
problem sounds like this sort. After it has converted the full URL to
a link, the pattern then finds the domain name as a URL within the
HREF attribute of your anchor (A) tag and then converts THAT to a link
so that the HTML ends up looking something like this (with angle
brackets substituted for the square ones below:

[a 
href="http://www.abc.com/"]subfolder/folder2/"]http://www.abc.com/subfolder/folder2/[/a]

4) If you needed to use stripslashes() on the value that you read from
the database you should probably do that before you pass the value to
makeLink(). However, if you've dealt successfully with #1 and #2 above
I doubt stripslashes() is necessary. Using addslashes() or
mysql_escape_string() does not mean the value is stored with the extra
escape characters, so there are no extra characters to remove when you
select it from the database.

Andrew

--- End Message ---
--- Begin Message ---
In my tests, Python can parse both Adler-32 and CRC32, while PHP can
only do Adler-32.

Anyways, I shortened my function:
        function fixAdler32($data) {
                static $f;
                if (!isset($f)) $f = tempnam('/tmp', 'gz_fix');
                file_put_contents($f, "\x1f\x8b\x08\x00\x00\x00\x00\x00" . 
$data);
                return file_get_contents('compress.zlib://' . $f);
        }
On Nov 7, 2007 7:42 AM, Per Jessen <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
>
> > They're exactly the same, except of the last 4 bytes. Python
> > calculates them differently than PHP. PHP follows the standards,
> > Python does not :]
>
> That is exactly what is so weird - does Python maybe have its own
> implementation of the gzip compression algorithm?   I would have
> thought they both used the same zlib.
>
>
>
> /Per Jessen, Zürich
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
Ford, Mike wrote:
> On 06 November 2007 12:57, Christoph Boget wrote:
> 
>> Consider the following test code:
> 
> [...snip...]
>  
>> Running that I found that
>>
>> if( isset( $myArray[$key] ))
>>
>> is faster than
>>
>> if( array key exists( $key, $myArray ))
>>
>> is faster than
>>
>> if( $myArray[$key] )
>>
>> To be honest, I was surprised.  I would have thought that if(
>> $myArray[$key] ) would have been the fastest way to check.  I'm
>> wondering if those in the know could explain why it's the slowest and
>> also where the discrepancies come from w/r/t the difference in the
>> amount of time it takes 
>> to make each
>> check.
> 
> OK, I'll take a stab.
> 
> Firstly, isset() is a language construct not an actual function, so the only 
> thing your isset() does is check whether the array element exists.
> 
> Next, array_key_exists() is the only one that involves a real function call, 
> so it's going to bear that cost. However, the function then does a pretty 
> simple test which again only involves checking whether the key exists, so the 
> function itself is going to be pretty quick.
> 
> Finally, the if() is the only one that actually gets the value in 
> $myArray[$key], and then casts it to Boolean to boot, and the cost of this 
> must therefore outweigh the cost of a function call plus a check for a key's 
> existence.
> 
> I'm certainly not surprised that isset() is the quickest, because it does the 
> simplest test, but to be honest I'm not sure if I'd have predicted the 
> relative positions of the other two..
> 
> Cheers!
> 
> Mike
> 

For convenience let's label the cases:
1: if( isset( $myArray[$key] ))
2: if( array key exists( $key, $myArray ))
3: if( $myArray[$key] )

Now, surely 3 is not comparable at all to 1 and 2.
Cases 1 and 2 check that the key exists in the array.
Case 3 does a boolean test on the value referenced by the key. That has several
consequences:
Firstly, if there is no element with key "$key" in the arrray, the interpreter
will throw an error (undefined index ...); this error could be suppressed and
ignored, I suppose.
Secondly, if the value referenced by the key is equivalent to FALSE, then the
test will return FALSE; for example, if you have set $myArray[$key]='' or
$myArray[$key]=0. This could be very confusing.

So if you want to test that the key exists, case 3 is NOT the way to do it. In
fact, you will often want to check that the key exists(with case 1, ideally)
BEFORE using a test of the form of case 3.

Cheers
Pete Ford (no relation, I think, although I do have a cousin called Michael...)

--- End Message ---
--- Begin Message ---
Just wondering if anyone uses an IDE and if so what ones?

Ta,

H. 

--- End Message ---
--- Begin Message ---
Zend Studio or
PHPEd


Regards,
Shelley

-----Original Message-----
From: Hulf [mailto:[EMAIL PROTECTED]
Sent: Thursday, November 08, 2007 6:02 PM
To: [EMAIL PROTECTED]
Subject: [PHP] PHP ide?

Just wondering if anyone uses an IDE and if so what ones?

Ta,

H.

--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: 
http://www.php.net/unsub.php


--- End Message ---
--- Begin Message ---
Eclipse with PDT plugin

IDE of champions ;)

Hulf wrote:
Just wondering if anyone uses an IDE and if so what ones?

Ta,

H.

--- End Message ---
--- Begin Message ---
Eclipse with PDT plugin

Scite. Not quite an IDE per-se, but still very very good and extremely versatile.

IDE of champions ;)

That somewhat subjective... :)

--
Richard Heyes
+44 (0)800 0213 172
http://www.websupportsolutions.co.uk

Knowledge Base and HelpDesk software
that can cut the cost of online support

--- End Message ---

Reply via email to