php-general Digest 31 Aug 2006 11:57:57 -0000 Issue 4322

Topics (messages 241250 through 241272):

Re: Free Shopping Carts
        241250 by: Jay Blanchard
        241257 by: Curt Zirzow

Re: Strange situation when saving a file
        241251 by: Andrew Kreps
        241259 by: Curt Zirzow

php generated javascript
        241252 by: Shu Hung (Koala)
        241253 by: Peter Lauri
        241254 by: Shu Hung (Koala)
        241255 by: J R
        241256 by: Curt Zirzow

RSS Creator
        241258 by: John Taylor-Johnston

Re: send a file or stream
        241260 by: Curt Zirzow

Re: Not using cached version
        241261 by: Curt Zirzow

Re: image manipulation with php
        241262 by: Curt Zirzow
        241266 by: Curt Zirzow

Re: file type and recode
        241263 by: Curt Zirzow
        241271 by: Martin Marques

Re: help - outputting a jpeg
        241264 by: Curt Zirzow

Re: Problems with UTF
        241265 by: Curt Zirzow

Re: Email with pregmatch
        241267 by: Curt Zirzow
        241268 by: Curt Zirzow

strip slashes from beginning and end of string in one expression
        241269 by: Dave M G
        241270 by: Stut
        241272 by: M. Sokolewicz

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 ---
[snip]
Are there free shopping carts that would work with 

PHP 5.0.X + and MySQL 4.1.X + and /or PostgresQL 8.1+ ?
[/snip]


Yes.





































You do have access to Google, right?

http://www.google.com/search?hl=en&lr=&q=free+open+source+shopping+cart+
php+5+mysql

--- End Message ---
--- Begin Message ---
On 8/30/06, Jay Blanchard <[EMAIL PROTECTED]> wrote:
[snip]
Are there free shopping carts that would work with

PHP 5.0.X + and MySQL 4.1.X + and /or PostgresQL 8.1+ ?
[/snip]


Yes.

Just in case:

Try google: 'php mysql shopping' cart or
'php pgsql shopping cart'

--- End Message ---
--- Begin Message ---
On 8/30/06, Miguel Guirao <[EMAIL PROTECTED]> wrote:
> Once the file has been created and saved as I doc file (not a doc
format!),
> I e-mail it!
>
> When the client gets the e-mail, he/she should open the file either by
> saving the file to the local system or openning the file directly from the
> e-mail attachment. Either way, I got a blank page in Word. If I open the
> document directly from the web server, without having it sent by e-mail,
it
> opens correctly in Word. The only problem is when the file is been
> emailed!!!

One problem could be the .doc extension.  A lot of email clients will
give you a warning at best, and at worst will completely remove the
attachment of things like Word documents, due to thier ability to
contain dangerous macros.  I don't think that is the problem you're
currently having, but it's good to be aware of.

Other than that, I would look at what add_attachment is actually doing
to see if it is indeed grabbing the correct file.

--- End Message ---
--- Begin Message ---
Please remove your 'this message is for the sole use of the person...'
thing or simply use a different account to ask questions..

On 8/29/06, Miguel Guirao <[EMAIL PROTECTED]> wrote:


Hi all,

I'm using ob_start() in order to save the content of a web page into a
variable string and then save it into a file in the file system. Every thing
is done OK. The only workaround I'm doing is adding a .doc file extension
when saving the file, in order to open the file in Word.

So you are adding a .doc extension so word can render the html file as
a wor doccument?


Once the file has been created and saved as I doc file (not a doc format!),
I e-mail it!

When the client gets the e-mail, he/she should open the file either by
saving the file to the local system or openning the file directly from the
e-mail attachment. Either way, I got a blank page in Word. If I open the
document directly from the web server, without having it sent by e-mail, it
opens correctly in Word. The only problem is when the file is been
emailed!!!

what you want to do is send the file you saved to a file as an
attatchment, if you are already doing so the problem is with how you
are composing the email that is sent to the client.

You are dealing with many issues, where the problem exists depends on
a lot of issues.

[snip]
Este mensaje es exclusivamente para el uso de la persona o entidad a quien esta 
dirigido;
[/snip]

again, do avoid using accounts that use this

Curt.

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

I'm writing a script to generate a javascript. The javascript would
generate a banner when it is sourced. This javascript is sourced
by another html like this:

<script type="text/javascript" language='JavaScript'
src='http://foo.com/testing/js.php'></script>

However, Sometimes the javascript doesn't show anything at all. it
seems that the php generated javascript cannot be loaded sometimes.
Maybe the generation takes too long. I'm not sure about that.

Is there anyway to deal with it?

Koala Yeung

--- End Message ---
--- Begin Message ---
Koala,

There is no difference with the php generated javascript and javascript on a
static html page.

Take a look at the source code of the page that has been generated in the
browser, and if that one looks as it should, it is probably your javascript
that is not doing what it should :)

And if that is the case you can join the [EMAIL PROTECTED] list for that
purpose.

/Peter



-----Original Message-----
From: Shu Hung (Koala) [mailto:[EMAIL PROTECTED] 
Sent: Thursday, August 31, 2006 10:41 AM
To: PHP General Users
Subject: [PHP] php generated javascript

Hello,

I'm writing a script to generate a javascript. The javascript would
generate a banner when it is sourced. This javascript is sourced
by another html like this:

<script type="text/javascript" language='JavaScript'
src='http://foo.com/testing/js.php'></script>

However, Sometimes the javascript doesn't show anything at all. it
seems that the php generated javascript cannot be loaded sometimes.
Maybe the generation takes too long. I'm not sure about that.

Is there anyway to deal with it?

Koala Yeung

--- End Message ---
--- Begin Message ---
On 8/31/06, Peter Lauri <[EMAIL PROTECTED]> wrote:

Koala,

There is no difference with the php generated javascript and javascript on
a
static html page.

Take a look at the source code of the page that has been generated in the
browser, and if that one looks as it should, it is probably your
javascript
that is not doing what it should :)

And if that is the case you can join the [EMAIL PROTECTED] list for
that
purpose.

/Peter


Petar,

Thanks for your reply.

I've used some server side cache for that javascript generation now.
It works a lot better. Seems to me that it takes too long to generate
the javascript. Sometimes browsers decided to ignores the javascript
and just run.

I used "document.write" in that javascript. When it isn't loaded
completely, nothing shows. I wonder if there is any better way.


Koala

--- End Message ---
--- Begin Message ---
put this at the top of your script "ob_start();" or before any output.

On 8/31/06, Shu Hung (Koala) <[EMAIL PROTECTED]> wrote:

On 8/31/06, Peter Lauri <[EMAIL PROTECTED]> wrote:
>
> Koala,
>
> There is no difference with the php generated javascript and javascript
on
> a
> static html page.
>
> Take a look at the source code of the page that has been generated in
the
> browser, and if that one looks as it should, it is probably your
> javascript
> that is not doing what it should :)
>
> And if that is the case you can join the [EMAIL PROTECTED] list for
> that
> purpose.
>
> /Peter
>
>
Petar,

Thanks for your reply.

I've used some server side cache for that javascript generation now.
It works a lot better. Seems to me that it takes too long to generate
the javascript. Sometimes browsers decided to ignores the javascript
and just run.

I used "document.write" in that javascript. When it isn't loaded
completely, nothing shows. I wonder if there is any better way.


Koala




--
GMail Rocks!!!

--- End Message ---
--- Begin Message ---
On 8/30/06, Shu Hung (Koala) <[EMAIL PROTECTED]> wrote:
On 8/31/06, Peter Lauri <[EMAIL PROTECTED]> wrote:
>
> Koala,
>
> There is no difference with the php generated javascript and javascript on
> a
> static html page.
>
> Take a look at the source code of the page that has been generated in the
> browser, and if that one looks as it should, it is probably your
> javascript
> that is not doing what it should :)
>
> And if that is the case you can join the [EMAIL PROTECTED] list for
> that
> purpose.
>
> /Peter
>
>
Petar,

Thanks for your reply.

I've used some server side cache for that javascript generation now.
It works a lot better. Seems to me that it takes too long to generate
the javascript. Sometimes browsers decided to ignores the javascript
and just run.

You might want to be more elaborate than that... What is considered
longer, What do you mean it ignores the javascript?

I used "document.write" in that javascript. When it isn't loaded
completely, nothing shows. I wonder if there is any better way.

This i dont understand, perhaps an example of what you are doing?

Curt.

--- End Message ---
--- Begin Message --- Has anyone created an RSS feed creator in PHP? I could make one fast enough, but ...
John

--
John Taylor-Johnston
-----------------------------------------------------------------------------
"If it's not Open Source, it's Murphy's Law."

'''    Cégep de Sherbrooke:
ô¿ô    http://www.cegepsherbrooke.qc.ca/languesmodernes/
 -     819-569-2064

 °v°   Bibliography of Comparative Studies in Canadian, Québec and Foreign 
Literatures
/(_)\  Université de Sherbrooke
 ^ ^   http://compcanlit.ca/ T: 819.569.2064

--- End Message ---
--- Begin Message ---
On 8/29/06, Rafael Mora <[EMAIL PROTECTED]> wrote:
Hi!

i want to send a file or output stream in a .php, but first compress it, I
tryed the example to compress files but how do i do to send as answer to the
http request??

Unlike my recent posts, this could be a candidate for using ob_*

There is no need to compress it first, just use ob_start('ob_gzhandler');

if the client supports a compression method, no special things are
needed and the content sent is compressed otherwise it is sent without
compression.

see http://php.net/ob-gzhandler for more info.

HTH,
Curt.

Curt.

--- End Message ---
--- Begin Message ---
On 8/30/06, Stut <[EMAIL PROTECTED]> wrote:
Peter Lauri wrote:
> I have some images stored in a database (only file name and other relevant
> information, rest stored in file system).
>
> I use the following html to access them:
>
> <img src='image.php?imageid=123' />
>
> At some pages I have the same image, so that tag will be seen on multiple
> places on the same page. So what I am curious is why all of the different
> images are loaded separately, instead of just recognizing that they are the
> same and use a cache version?
>
> This is the code that do all the work:
>
>   Header ("Content-type: $image_type");
>   readfile("files/$image");
>
> I am a little bit lost here; kick me in the right direction if you can :)
>

Probably because the browser sees the ? in the URL, thinks dynamic and
doesn't cache the result. You can set caching headers to get around this

You also have to remember that php by default sends the headers to
prevent caching, take a look at the headers responded via a static
.jpg file and a php page tha sends an image; You'll notice all those
extra no-cache type headers that enforce any browser to not reload a
(local) cached version of the file.

To get best performance
 support a HEAD request:
   send last-modified: and content-length: with the orignal sending
of the file and within your php script if the client requests a
IF_MODIFIED_SINCE header check the header against the value, if it
matches respond with something like:
  header('HTTP/1.0 304 Not modified');
  exit;

 support partial requests:
  check for the http header for partial content requests (I forget
the name, perhaps someone can remind me of it) and respond according
to the http specs.

HTH,
Curt.

(Google for it), or if you want *all* browsers to do it right, even the
poorly implemented ones, you could modify the URL so it doesn't have the
?. I do this using the Apache MultiViews option and a URL similar to
/image/123.gif. That actually runs /image.php which pulls the
REQUEST_URI server variable apart to get the required image. Do both and
you should be good for all browsers.

-Stut

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



--- End Message ---
--- Begin Message ---
On 8/29/06, Ross <[EMAIL PROTECTED]> wrote:

I have an saved images I output with this...


<img src="includes/viewphoto.php?id=<?=$photo?>">


I want to use getimagesize() to get the height and width of the image and if
it is above a certain size then scale/ reduce it.

The problems are

(i) using getimage() without a url just my viewphoto.php script

I'm not sure what you mean here.


(ii) comparing and reducing  the file

reducing a file tends to follow the logic of some sort:

  $size = GetImageSize ($image);
   $ratio = $size[0]/$size[1];
   if ($ratio > 1) {
     $width = $max_size;
     $height = ($max_size/$size[0]) * $size[1];
   } else {
     $width = ($max_size/$size[1]) * $size[0];
     $height = $max_size;
   }

where $max_size is the largest you want your image to be in width,
then just copy it it into a new image create at that size

There are a lot of samples of this on google as jochem suggested.

Curt.

--- End Message ---
--- Begin Message ---
On 8/29/06, zerof <[EMAIL PROTECTED]> wrote:
http://www.educar.pro.br/abc/gdlib/index.php?pageNum_rsNVER=22&totalRows_rsNVER=67
----
zerof

speako englisho, solo

--- End Message ---
--- Begin Message ---
On 8/29/06, Martin Marques <[email protected]> wrote:
Simple question:

Is there a built-in function in PHP to get the charset of a file, so that
I can pass the right parameters to recode_file()?

It depends.

If it is a .txt file (nope)
a .doc file (mabey, pending the .doc format)
a .xml file (most likely, unless it is a poorly formatted xml file)

It all depends how the document is stored and if it keeps the charset
within the document.

Curt.

--- End Message ---
--- Begin Message ---
On Wed, 30 Aug 2006, Curt Zirzow wrote:

On 8/29/06, Martin Marques <[email protected]> wrote:
Simple question:

Is there a built-in function in PHP to get the charset of a file, so that
I can pass the right parameters to recode_file()?

It depends.

If it is a .txt file (nope)
a .doc file (mabey, pending the .doc format)
a .xml file (most likely, unless it is a poorly formatted xml file)

It all depends how the document is stored and if it keeps the charset
within the document.

I want something more like the output of the unix command "file -i" (without running a system call). And yes, they are text files.

--
 21:50:04 up 2 days,  9:07,  0 users,  load average: 0.92, 0.37, 0.18
---------------------------------------------------------
Lic. Martín Marqués         |   SELECT 'mmarques' ||
Centro de Telemática        |       '@' || 'unl.edu.ar';
Universidad Nacional        |   DBA, Programador,
    del Litoral             |   Administrador
---------------------------------------------------------

--- End Message ---
--- Begin Message ---
On 8/29/06, Ross <[EMAIL PROTECTED]> wrote:
I just get all the binary data output

<?
include("includes/config.php");
$link = mysql_connect($host, $user, $password) or die ('somethng went
wrong:' .mysql_error() );
  mysql_select_db($dbname, $link) or die ('somethng went wrong, DB error:'
.mysql_error() );

$query = "SELECT DISTINCT gallery FROM thumbnails";
$result = @mysql_query( $query,$link );

and also dont use @ to suppress errors it will cause your more
problems, turn off display_errors and keep error_reportlng at minimum
E_WARNING, and log the errors to a file.

Curt.

--- End Message ---
--- Begin Message ---
:: top posted to be consistant::

I would go as far as configuring your default php.ini to send utf-8 as
the default charset.

Curt.

On 8/28/06, Peter Lauri <[EMAIL PROTECTED]> wrote:
Hi,

Have you set

header('Content-Type: text/html; charset=utf-8');

in your php script that you call via AJAX?


-----Original Message-----
From: mbneto [mailto:[EMAIL PROTECTED]
Sent: Tuesday, August 29, 2006 2:57 AM
To: [email protected]
Subject: [PHP] Problems with UTF

Hi,

I have a php based script that is called from a html page via ajax.
Everything runs fine except when I use characters such as á that ends up
like A!

After searching and testing I found that if I remove the
encodeURIComponentfrom the javascript and replace with
escape everything works fine.

So the question is what can I do from PHP side to make it play nice with
those UTF encoded chars generated from encodeURIComponent?  Since escape is
deprecated I'd like to find out before I have tons of files to change....

tks.


--- End Message ---
--- Begin Message ---
On 8/27/06, Dave Goodchild <[EMAIL PROTECTED]> wrote:
Try this:

preg_match("/^([a-zA-Z0-9.])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/",
$_POST['email']);

So:
[EMAIL PROTECTED]

is valid?

Curt.

--- End Message ---
--- Begin Message ---
On 8/27/06, Peter Lauri <[EMAIL PROTECTED]> wrote:
I found this on google, does this LONG function do anything more then your
preg_match?

i think a combo of what the function does and a few regex's will work.
The issue is more on how idoes it pass all the rfc's on each part of
the address, for a quick reference of rfc's:

 http://en.wikipedia.org/wiki/E-mail_address

An address consists of:
 [EMAIL PROTECTED]

so the question is does it pass local tests, which should be rather
simple, the domain part gets rather complcated since you cant predict
at what domain level we are talking about:

 [EMAIL PROTECTED]
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]


There is a pcre expression out there somewhere in perl land that is
considered to validate all the rfc requirements of the address and is
about 50 lines worth of regular expressions with a lot of backward
matching and forward matching conditions.

So the only simple logic you can really apply is split on  the @; is
local ok? are each part of the domains valid according to the rfc's.
typically it is safe to say if they put at least two periods in a name
and the characters between those periods are valid chars then it is a
valid input ( of course it doesn't mean it is a valid email)

I suppose the least you want to do is limit addresses people can use so:
 local <~~ assumed invalid (no @), unless you only want local addresses
 [EMAIL PROTECTED] <~~ assumed invalid since there is no tld (unless you
want a local address)
 everything else is valid (as long as it passes all the tests)

So with that you want an expression that allows for:
 (valid_local){1}@(valid_domain.)+(valid_tld){1}

where:
 valid_local = a valid local addres
 valid_domain = a valid domain name
 valid_tld = a valid tld
 . = period (dot)
 {1} = must match once
 + = must have 1, can have more

Making a pcre expression can get complicated, breaking it apart and
validating each section will probably make it easier to deal with.


Curt.

--- End Message ---
--- Begin Message ---
PHP list.

This is another regular expression type of question.

The very handy PHP function trim() takes excess white space off the beginning and end of a string.

I'd like to be able to do the same thing, except instead of white spaces, trim excess slashes: /

So for example, all of these:
/this/that/
/this/that
this/that/
////////this/that////////////

... become:
this/that

There is also the chance of more than one slash occurring inside the desired text:
/this/that/this/that/

So that would also need to be accounted for. The above example should become:
this/that/this/that

I think I need to use preg_replace() for this, but, as ever, regular expressions completely throw me.

If I'm not mistaken, "#^/*#" should get me the first slash of the string, and more if there are more. And "#*/$#" should get me the last slash of the string, and more if there are more.

Can I test for the first and last slash in the same expression?

I think I either need something between the two that says "ignore what's in the middle", or and and/or statement to say "replace if this occurs at the end, or at the beginning, or both".

I've looked around and can't seem to find a way of connecting these in the same search. However, I'm sure that is because I'm not familiar enough with regular expressions to know what I'm looking at.

How would I connect "#^/*#" and "#*/$#" into one regular expression?

Thank you for your time and advice.

--
Dave M G
Ubuntu 6.06 LTS
Kernel 2.6.17.7
Pentium D Dual Core Processor
PHP 5, MySQL 5, Apache 2

--- End Message ---
--- Begin Message ---
Dave M G wrote:
This is another regular expression type of question.

The very handy PHP function trim() takes excess white space off the beginning and end of a string.

I'd like to be able to do the same thing, except instead of white spaces, trim excess slashes: /

So for example, all of these:
/this/that/
/this/that
this/that/
////////this/that////////////

... become:
this/that

Why do people insist on over-complicating things with regexes? They're not the best tool for every job!

Read the manual page for the trim function (http://php.net/trim) and try using the second parameter.

-Stut

--- End Message ---
--- Begin Message ---
Dave M G wrote:
PHP list.

This is another regular expression type of question.

The very handy PHP function trim() takes excess white space off the beginning and end of a string.

I'd like to be able to do the same thing, except instead of white spaces, trim excess slashes: /

So for example, all of these:
/this/that/
/this/that
this/that/
////////this/that////////////

... become:
this/that

There is also the chance of more than one slash occurring inside the desired text:
/this/that/this/that/

So that would also need to be accounted for. The above example should become:
this/that/this/that

I think I need to use preg_replace() for this, but, as ever, regular expressions completely throw me.

If I'm not mistaken, "#^/*#" should get me the first slash of the string, and more if there are more. And "#*/$#" should get me the last slash of the string, and more if there are more.

Can I test for the first and last slash in the same expression?

I think I either need something between the two that says "ignore what's in the middle", or and and/or statement to say "replace if this occurs at the end, or at the beginning, or both".

I've looked around and can't seem to find a way of connecting these in the same search. However, I'm sure that is because I'm not familiar enough with regular expressions to know what I'm looking at.

How would I connect "#^/*#" and "#*/$#" into one regular expression?

Thank you for your time and advice.

--
Dave M G
Ubuntu 6.06 LTS
Kernel 2.6.17.7
Pentium D Dual Core Processor
PHP 5, MySQL 5, Apache 2


something like
$trimmed = preg_replace('#^/*(.+)/*$#m', '$1', $string)
should work

--- End Message ---

Reply via email to