php-general Digest 29 Jul 2009 18:40:02 -0000 Issue 6256

2009-07-29 Thread php-general-digest-help

php-general Digest 29 Jul 2009 18:40:02 - Issue 6256

Topics (messages 295995 through 296014):

Re: GeoIP Character Encoding
295995 by: Nisse Engström
295997 by: Nisse Engström

Re: Broken IF behavior? (Changing the branch changes the evaluation)
295996 by: Peter Ford
296006 by: Matt Neimeyer
296008 by: Ford, Mike
296009 by: Shawn McKenzie

Re: Message Board Recommendations
295998 by: Al
295999 by: Floyd Resler

Re: Argh Date problems (RESOLVED)
296000 by: Miller, Terion

Re: How to Install Roadsend Compiler on Fedora
296001 by: Jim Lucas

Ridiculous ..won't print or echo ...
296002 by: Miller, Terion
296003 by: Aipok
296004 by: Ashley Sheridan
296007 by: Ford, Mike

Re: Ridiculous ..won't print or echo ...(RESOLVED)
296005 by: Miller, Terion

preg_match too greedy
296010 by: b
296011 by: Jim Lucas

Getting rid of extra lines
296012 by: Miller, Terion
296013 by: Ashley Sheridan
296014 by: Miller, Terion

Administrivia:

To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
php-gene...@lists.php.net


--
---BeginMessage---
On Tue, 28 Jul 2009 18:10:33 -0400, APseudoUtopia wrote:

 'Portugal, 09, Vila Real De Santo António'
 'Norway, 08, Ålesund'
 'Portugal, 04, Vila Nova De Famalicão'
 
 (Note the ó, Å, and ã).
 
 I'm using PostgreSQL as my database. The database's encoding is UTF8,
 and the locale is C.
 
 When I try to insert the above strings into a VARCHAR column, I get
 errors similar to the following:
 
 ERROR:  invalid byte sequence for encoding UTF8: 0xf36e696f
 ERROR:  invalid byte sequence for encoding UTF8: 0xc56c
 ERROR:  invalid byte sequence for encoding UTF8: 0xe36f2c
 
 Now, I believe I can solve the problem by changing the client_encoding
 of my postgresql client (Right now, it is set to UTF8). However, I'm
 trying to figure out what encoding the GeoIP function is returning to
 me so that I can set the client_encoding appropriately. Is it LATIN1?
 How can I figure it out? And can I change it to UTF8?

The hex sequences are consistent with ISO-8859-1 (aka latin1).
You may want to check out mbstring, iconv or recode:

http://se.php.net/manual/en/refs.international.php


/Nisse
---End Message---
---BeginMessage---
On Tue, 28 Jul 2009 18:10:33 -0400, APseudoUtopia wrote:

 I'm using the PECL GeoIP module on php 5.2.10. When I look up an IP
 address, the geoip_record_by_name() function is giving me a string
 that contains special characters, such as the following:

The PECL GeoIP page links to http://www.maxmind.com/, and a
search for charset reveals the following:


http://forum.maxmind.com/viewtopic.php?p=2031highlight=

quote

the binary database return the cityname in iso-8859-1 by default.
I guess your output is in a different charset. 

The CAPI based wrappers have a set_charset method. 

If you use any other API, use the language charset encoding to
transform iso-8859-1 into the desired output format. 

for php you might use: 

   Code:
   $city = mb_convert_encoding( $old_city, 'UTF-8', 'ISO-8859-1');

or 

   Code:
   $city =  utf8_encode ( $oold_city )

/quote


/Nisse
---End Message---
---BeginMessage---
Matt Neimeyer wrote:
 It's exactly what I would expect... The content of the row... But in
 any case, what does changing the content of the { } branch have to do
 with how the IF() itself is evaluated?
 
 array(4) {
   [0]=
   string(8) CustName
   [config]=
   string(8) CustName
   [1]=
   string(11) Sample Cust
   [value]=
   string(11) Sample Cust
 }
 
 

The if() *is* being evaluated *the same* whatever the content of that branch,
but when there's no content, you see no result...

It always looks odd to me to have empty if branches - why do you not just write

if ($Ret) { return $Ret; }

Anyway, the !$Ret branch is being executed because the fetch operation will
return NULL (or FALSE or something equivalent) when there are no results.



-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent
---End Message---
---BeginMessage---
 $Ret = mysql_fetch_array($result); if(!$Ret) { } else { return $Ret; }
 I'm assuming that you are calling my_fetch_array() in a loop of some
 sort and so at some point there are no more records in the result.

Oh... Um... Yeah... Well... headdesk

So... Checking the docs... Returns an array of strings that
corresponds to the fetched row, or FALSE if there are no more rows.

Is there a way to differentiate between a FALSE for no more rows and an error?

Matt
---End Message---
---BeginMessage---
 

[PHP] How to Install Roadsend Compiler on Fedora

2009-07-29 Thread Javed Khan
Can something please show me to install Roadsend Compiler on Fedora 10. 
Thank you, 
J.K 


  

[PHP] Re: GeoIP Character Encoding

2009-07-29 Thread Nisse Engström
On Tue, 28 Jul 2009 18:10:33 -0400, APseudoUtopia wrote:

 'Portugal, 09, Vila Real De Santo António'
 'Norway, 08, Ålesund'
 'Portugal, 04, Vila Nova De Famalicão'
 
 (Note the ó, Å, and ã).
 
 I'm using PostgreSQL as my database. The database's encoding is UTF8,
 and the locale is C.
 
 When I try to insert the above strings into a VARCHAR column, I get
 errors similar to the following:
 
 ERROR:  invalid byte sequence for encoding UTF8: 0xf36e696f
 ERROR:  invalid byte sequence for encoding UTF8: 0xc56c
 ERROR:  invalid byte sequence for encoding UTF8: 0xe36f2c
 
 Now, I believe I can solve the problem by changing the client_encoding
 of my postgresql client (Right now, it is set to UTF8). However, I'm
 trying to figure out what encoding the GeoIP function is returning to
 me so that I can set the client_encoding appropriately. Is it LATIN1?
 How can I figure it out? And can I change it to UTF8?

The hex sequences are consistent with ISO-8859-1 (aka latin1).
You may want to check out mbstring, iconv or recode:

http://se.php.net/manual/en/refs.international.php


/Nisse

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



Re: [PHP] Broken IF behavior? (Changing the branch changes the evaluation)

2009-07-29 Thread Peter Ford
Matt Neimeyer wrote:
 It's exactly what I would expect... The content of the row... But in
 any case, what does changing the content of the { } branch have to do
 with how the IF() itself is evaluated?
 
 array(4) {
   [0]=
   string(8) CustName
   [config]=
   string(8) CustName
   [1]=
   string(11) Sample Cust
   [value]=
   string(11) Sample Cust
 }
 
 

The if() *is* being evaluated *the same* whatever the content of that branch,
but when there's no content, you see no result...

It always looks odd to me to have empty if branches - why do you not just write

if ($Ret) { return $Ret; }

Anyway, the !$Ret branch is being executed because the fetch operation will
return NULL (or FALSE or something equivalent) when there are no results.



-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



[PHP] Re: GeoIP Character Encoding

2009-07-29 Thread Nisse Engström
On Tue, 28 Jul 2009 18:10:33 -0400, APseudoUtopia wrote:

 I'm using the PECL GeoIP module on php 5.2.10. When I look up an IP
 address, the geoip_record_by_name() function is giving me a string
 that contains special characters, such as the following:

The PECL GeoIP page links to http://www.maxmind.com/, and a
search for charset reveals the following:


http://forum.maxmind.com/viewtopic.php?p=2031highlight=

quote

the binary database return the cityname in iso-8859-1 by default.
I guess your output is in a different charset. 

The CAPI based wrappers have a set_charset method. 

If you use any other API, use the language charset encoding to
transform iso-8859-1 into the desired output format. 

for php you might use: 

   Code:
   $city = mb_convert_encoding( $old_city, 'UTF-8', 'ISO-8859-1');

or 

   Code:
   $city =  utf8_encode ( $oold_city )

/quote


/Nisse

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



[PHP] Re: Message Board Recommendations

2009-07-29 Thread Al



tedd wrote:

Hi gang:

I have a client who is looking for a Message Board for Subscribers to 
be installed on his site -- one with a good admin. Any recommendations?


Thanks,

tedd


If your request is for a forum type, then SMF is super 
http://www.simplemachines.org

If the need is for a communications registry, then my MiniRegDB might fit the 
bill, using the Private/Secure mode.

http://ridersite.org/MiniRegDBdemo/MiniRegDBoverview.php

If neither of these fits the need, describe it in more detail.

Al.

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



Re: [PHP] Re: Message Board Recommendations

2009-07-29 Thread Floyd Resler


On Jul 29, 2009, at 8:44 AM, Al wrote:




tedd wrote:

Hi gang:
I have a client who is looking for a Message Board for  
Subscribers to be installed on his site -- one with a good admin.  
Any recommendations?

Thanks,
tedd


If your request is for a forum type, then SMF is super 
http://www.simplemachines.org

If the need is for a communications registry, then my MiniRegDB  
might fit the bill, using the Private/Secure mode.

http://ridersite.org/MiniRegDBdemo/MiniRegDBoverview.php

If neither of these fits the need, describe it in more detail.

Al.

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




I've always liked phpBB3.

Take care,
Floyd


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



Re: [PHP] Argh Date problems (RESOLVED)

2009-07-29 Thread Miller, Terion
I had a tiny syntax error keeping it from working in the form of a cap letter.



On 7/28/09 3:51 PM, Miller, Terion tmil...@springfi.gannett.com wrote:




On 7/28/09 3:48 PM, Bastien Koert phps...@gmail.com wrote:

On Tue, Jul 28, 2009 at 4:02 PM, Miller,
Teriontmil...@springfi.gannett.com wrote:
 Ok so I got the
 $inDate = strtotime($results[3][$i]);

 Giving me the unix date now I am trying all the different date functions that 
 will put it in the -00-00 like sql stores it because I ran it with the 
 unix stamp and it just stored 00 in the db

 Hoping something like this works?
  $formatDate = date('ymd', $inDate);


 On 7/28/09 2:41 PM, Miller, Terion tmil...@springfi.gannett.com wrote:

 Well I was going along smoothly from this morningbut it came down to
 having to change the field type to date in the mySQL..so now I have this
 which returns a scraped value formatted like this 0/00/00 m/d/y

  $inDate = $results[3][$i];

 Which date function can I use to format for the db so that I will be able to
 use range references...there are so many get_date, date_modifyI'm
 lost...

 My full code is this:

 preg_match_all('/pfont size=2 face=Arial, Helvetica,
 sans-serif(.+)br(.+)br.+(\d+\/\d+\/\d+)\s(.+)br(.+)br.+Critical
 Violations Found:.+(\d+)(.+)Noncritical Violations Found:.+(\d+)/imsSU',
 utf8_encode($url), $results);



 for ($i=0; $i  count($results[0]); $i++)
 {
$name1 = strtolower($results[1][$i]);

$name =
 ltrim($name1);

$address = strtolower($results[2][$i]);

$inDate
 = $results[3][$i];

$inType = $results[4][$i];

$notes =
 trim($results[5][$i]);

$critical = trim($results[6][$i]);


 echo $noncritical brhr;



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




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



Can't you just explode the string and put it back together in the
/MM/DD format that you need?

--

Bastien

Cat, the other other white meat


Well I got it all formatted and going in the db right and now I'm able to use 
the BETWEEN in my sql and it works like a charm but when I echo the date for 
the page I need to put it back in mm/dd/ order and that part is giving me 
problems...
Not getting why since I figured I could do this again:

$date = $row['inDate'];$formatDate = date('mdy', $Date);

But at any rate it's nearly beer o'clock here hooray, and I'm feeling like 
today I have earned one or two!!
Until tomorrow
Terion


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



Re: [PHP] How to Install Roadsend Compiler on Fedora

2009-07-29 Thread Jim Lucas
Javed Khan wrote:
 Can something please show me to install Roadsend Compiler on Fedora 10. 
 Thank you, 
 J.K 
 
 
   

Why don't you look at Roadsend for the question.

http://code.roadsend.com/pcc/wiki/BuildInstructions

The PHP mailing list is not a support group for Roadsend.

If you need support for them, try their forum or IRC channels.

Jim


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



[PHP] Ridiculous ..won't print or echo ...

2009-07-29 Thread Miller, Terion
Ok in my output to Quark I need to have $P printed to the page like this:

@$p2118 S. Campbell Ave

So in my php which is going to be grabbing this info and formatting it for
the Quarkisn't echoing that $p all I get is the @

I have tried several things:

$p = $p

$p = print($p)

$p = echo $p

On and on...

tried all kinds of ways to just get a $p to print to the page.and I can
not for some reason get a $p to print to the page...what's up with that...


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



RE: [PHP] Ridiculous ..won't print or echo ...

2009-07-29 Thread Aipok
Ok in my output to Quark I need to have $P printed to the page like this:

@$p2118 S. Campbell Ave

So in my php which is going to be grabbing this info and formatting it for
the Quarkisn't echoing that $p all I get is the @

I have tried several things:

$p = $p

$p = print($p)

$p = echo $p

On and on...

tried all kinds of ways to just get a $p to print to the page.and I can
not for some reason get a $p to print to the page...what's up with that...


Try with $p = '$p' to store the string $p inside the $p variable. Or, use
echo '$p' (without the double quotes). $p = echo $p makes no sense, as
the echo function doesn't return anything, and you're trying to store the
returning result (none) into the variable $p.


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



Re: [PHP] Ridiculous ..won't print or echo ...

2009-07-29 Thread Ashley Sheridan
On Wed, 2009-07-29 at 11:36 -0400, Miller, Terion wrote:
 Ok in my output to Quark I need to have $P printed to the page like this:
 
 @$p2118 S. Campbell Ave
 
 So in my php which is going to be grabbing this info and formatting it for
 the Quarkisn't echoing that $p all I get is the @
 
 I have tried several things:
 
 $p = $p
 
 $p = print($p)
 
 $p = echo $p
 
 On and on...
 
 tried all kinds of ways to just get a $p to print to the page.and I can
 not for some reason get a $p to print to the page...what's up with that...
 
 
PHP is seeing the $ and thinking that $p is a variable. As you have
errors and notices turned off, you aren't seeing the notice that you are
trying to use an undefined variable.

There are several ways to get round this:

  * escape like \$
  * put the $p inside of single quotes in your echo
  * use an escape code for the dollar

Thanks,
Ash
http://www.ashleysheridan.co.uk


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



Re: [PHP] Ridiculous ..won't print or echo ...(RESOLVED)

2009-07-29 Thread Miller, Terion
Yep just figured that out too..the escaping thing..
Thanks


On 7/29/09 10:45 AM, Ashley Sheridan a...@ashleysheridan.co.uk wrote:

On Wed, 2009-07-29 at 11:36 -0400, Miller, Terion wrote:
 Ok in my output to Quark I need to have $P printed to the page like this:

 @$p2118 S. Campbell Ave

 So in my php which is going to be grabbing this info and formatting it for
 the Quarkisn't echoing that $p all I get is the @

 I have tried several things:

 $p = $p

 $p = print($p)

 $p = echo $p

 On and on...

 tried all kinds of ways to just get a $p to print to the page.and I can
 not for some reason get a $p to print to the page...what's up with that...


PHP is seeing the $ and thinking that $p is a variable. As you have
errors and notices turned off, you aren't seeing the notice that you are
trying to use an undefined variable.

There are several ways to get round this:

  * escape like \$
  * put the $p inside of single quotes in your echo
  * use an escape code for the dollar

Thanks,
Ash
http://www.ashleysheridan.co.uk




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



Re: [PHP] Re: Broken IF behavior? (Changing the branch changes the evaluation)

2009-07-29 Thread Matt Neimeyer
 $Ret = mysql_fetch_array($result); if(!$Ret) { } else { return $Ret; }
 I'm assuming that you are calling my_fetch_array() in a loop of some
 sort and so at some point there are no more records in the result.

Oh... Um... Yeah... Well... headdesk

So... Checking the docs... Returns an array of strings that
corresponds to the fetched row, or FALSE if there are no more rows.

Is there a way to differentiate between a FALSE for no more rows and an error?

Matt

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



RE: [PHP] Ridiculous ..won't print or echo ...

2009-07-29 Thread Ford, Mike
 -Original Message-
 From: Miller, Terion [mailto:tmil...@springfi.gannett.com]
 Sent: 29 July 2009 16:36
 
 Ok in my output to Quark I need to have $P printed to the page like
 this:
 
 @$p2118 S. Campbell Ave
 
 So in my php which is going to be grabbing this info and formatting
 it for
 the Quarkisn't echoing that $p all I get is the @
 
 I have tried several things:
 
 $p = $p
 
 $p = print($p)

$p is trying to interpolate the value of the variable $p -- if you had full 
error reporting turned on, you would see a nonexistent variable error. Once 
more, there are several things you can do, of which the two most obvious are:

* Use single quotes: echo '$p';

* Use a backslash: echo \$p;


Cheers!

Mike
 -- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Leeds Metropolitan University, C507, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom 
Email: m.f...@leedsmet.ac.uk 
Tel: +44 113 812 4730





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

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



RE: [PHP] Re: Broken IF behavior? (Changing the branch changes the evaluation)

2009-07-29 Thread Ford, Mike
 -Original Message-
 From: Matt Neimeyer [mailto:m...@neimeyer.org]
 Sent: 29 July 2009 16:47
 
  $Ret = mysql_fetch_array($result); if(!$Ret) { } else { return
 $Ret; }
  I'm assuming that you are calling my_fetch_array() in a loop of
 some
  sort and so at some point there are no more records in the result.
 
 Oh... Um... Yeah... Well... headdesk
 
 So... Checking the docs... Returns an array of strings that
 corresponds to the fetched row, or FALSE if there are no more rows.
 
 Is there a way to differentiate between a FALSE for no more rows and
 an error?

I don't actually think that mysql_fetch_array can return an error -- read that 
description again, it's very clear that you get an array of fetched values or 
FALSE for no more data, no other options. If there's any error occurring, it 
will be in the preceding mysql_query().


Cheers!

Mike
 -- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Leeds Metropolitan University, C507, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom 
Email: m.f...@leedsmet.ac.uk 
Tel: +44 113 812 4730




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

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



Re: [PHP] Re: Broken IF behavior? (Changing the branch changes the evaluation)

2009-07-29 Thread Shawn McKenzie
Ford, Mike wrote:
 -Original Message-
 From: Matt Neimeyer [mailto:m...@neimeyer.org]
 Sent: 29 July 2009 16:47

 $Ret = mysql_fetch_array($result); if(!$Ret) { } else { return
 $Ret; }
 I'm assuming that you are calling my_fetch_array() in a loop of
 some
 sort and so at some point there are no more records in the result.
 Oh... Um... Yeah... Well... headdesk

 So... Checking the docs... Returns an array of strings that
 corresponds to the fetched row, or FALSE if there are no more rows.

 Is there a way to differentiate between a FALSE for no more rows and
 an error?
 
 I don't actually think that mysql_fetch_array can return an error -- read 
 that description again, it's very clear that you get an array of fetched 
 values or FALSE for no more data, no other options. If there's any error 
 occurring, it will be in the preceding mysql_query().
 

Probably the only error you can get is: supplied argument is not a valid
MySQL result resource, if $result is not valid.  So you could check that
in the code that does the actual query.

As for the function, I would just do this:

function my_fetch_array($result)
{
if(version_compare($GLOBALS['Version'], 2.0, =)) {
return mysql_fetch_array($result);
} else {
return odbtp_fetch_array($result);
}
}

-- 
Thanks!
-Shawn
http://www.spidean.com

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



[PHP] preg_match too greedy

2009-07-29 Thread b
I'm trying to figure out how to test if a string matches *exactly* 
another string, using a regexp pattern. The manual says that ereg() is 
deprecated (in favour of what?) and preg_match() is giving me trouble. 
The problem is that I'm passing the end-of-line delimiter ($) but it 
seems to be ignored. An example:


-- snip --
header('Content-type: text/plain');
$url = '/foo(/)?';
$test = 'foo/bar';
$pattern = '%^'.$url.'$%U';

echo ${url} :: ${test}\n;

echo (preg_match($pattern, $test) != false)
? 'match'
: 'no match';
-- snip --

I expected 'no match' but get 'match'.

The reason for the (/)? is to allow for a trailing slash. I've added a 
'$' to specify that I want to test for the exact string. However, 
preg_match() tests for the existence of a string and appears to ignore 
the '$'.


How do I do this?

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



Re: [PHP] Getting rid of extra lines

2009-07-29 Thread Miller, Terion



On 7/29/09 1:34 PM, Ashley Sheridan a...@ashleysheridan.co.uk wrote:

On Wed, 2009-07-29 at 11:29 -0700, Miller, Terion wrote:
 I am trying to get rid of empty whitespace lines, I can't us chop() because
 as I read it it will remove all whitespacesright?

 Right now my db is outputting with extra lines, I have stripped tags I know
 it isn't that causing it to look like this

 Blahlajdlkfjlksdjflkdjsf

--how do I get rid of all this extra space?

 alkdfjlsdakjflsakdjflksjdf


Some example of where this is occurring in your code might help. HTML
output will ignore whitespace such as this unless it is asked explicitly
to preserve it, with a pre tag or CSS.

Thanks
Ash
www.ashleysheridan.co.uk



Well the html displays fine, its when I view the CSV in the db, I see the extra 
space, and I'm writing an application to reverse publish some of our site 
materials to the paper (I work for a newspaper) and the Quark output is picking 
up that extra space that is in the db (does that make sense?)

Here is what the CSV looks like (See all that linespacing?)  :

;2009-01-20;Inspection;Will re-test dishwashing machine and sanitizer 
buckets for proper concentration, in addition to reviewing critical items, 
during time of re-inspection.;5;




 Employee drink found uncovered, sitting next to clean bin of eating 
utensils. This is a repeat violation.












 Sanitizer bucket holding wiping cloths was found at 0 ppm chlorine; must 
maintain concentration of solution at 50-100ppm chlorine to effectively 
sanitize food contact surfaces.






 Can opener blade found encrusted with dust and dried-on, black, food 
debris; must maintain clean food contact surfaces under frequent cleaning 
regiment, so as to not risk cross-contamination to food.






 Dishwashing machine found not effectively sanitizing as it measured 0 ppm 
chlorine; must maintain dishwasher so that it consistently and adequately 
sanitizes food contact surfaces. Corrected on site. This is a repeat violation.


My code for the original insertion to the db is this(shortened up though)

or ($i=0; $i  count($results[0]); $i++) {$name1 = 
strtolower($results[1][$i]);$name = ltrim($name1);$address = 
strtolower($results[2][$i]);$inDate = strtotime($results[3][$i]);   
 $inType = strip_tags($results[4][$i]);$notes = 
strip_tags($results[5][$i]); $critical = strip_tags($results[6][$i]);   
 $cviolations = strip_tags($results[7][$i]);$noncritical = 
$results[8][$i];//trying to manipulate different field data
$cleanViolations = str_replace('*', '', $cviolations);$ucName = 
ucwords($name);$ucAddress = ucwords($address);$formatDate = date('ymd', 
$inDate);  //escaping strings good coder$mysql_name = 
mysql_escape_string($ucName);$mysql_address = 
mysql_escape_string($ucAddress);$mysql_inDate = 
mysql_escape_string($formatDate);$mysql_inType = 
mysql_escape_string($inType);$mysql_notes = mysql_escape_string($notes);
$mysql_critical = mysql_escape_string($critical);$mysql_cviolations = 
mysql_escape_string($cleanViolations);$mysql_noncritical = 
mysql_escape_string($noncritical);   //insert each to the database   
//attempt loop for checking restaurants // First check if the name exists $sql 
=SELECT * FROM `restaurants` WHERE `name`='{$mysql_name}' AND `address` 
='{$mysql_address}'; $result = mysql_query($sql) or die(mysql_error()); if 
(mysql_num_rows($result)  0){ $row = mysql_fetch_array($result);   $ID = 
$row['ID'];   // This means the name exists.. UPDATE inspections table
$sql = INSERT INTO `inspections` (ID, inDate, inType, notes, critical, 
cviolations, noncritical)  VALUES (;$sql .= '$ID', '$mysql_inDate', 
'$mysql_inType', '$mysql_notes', '$mysql_critical', '$mysql_cviolations', 
'$mysql_noncritical');mysql_query($sql); } else{// The 
name doesn't exists, add all the info  $sql = INSERT INTO `restaurants` 
(name, address)  VALUES (;  $sql .=  '$mysql_name', '$mysql_address');   
 mysql_query($sql); $ID = mysql_insert_id(); $sql = INSERT 
INTO `inspections` (ID, inDate, inType, notes, critical, cviolations, 
noncritical)  VALUES (;$sql .=  '$ID', '$mysql_inDate', '$mysql_inType', 
'$mysql_notes', '$mysql_critical', '$mysql_cviolations', 
'$mysql_noncritical');mysql_query($sql); } /**/ };





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



Re: [PHP] Getting rid of extra lines

2009-07-29 Thread Ashley Sheridan
[snip/]

Have you thought of just using a regular str_replace() on your code? You
can ask it to replace newlines and carriage returns with nothing and see
if that fixes you problem?

Thanks
Ash
www.ashleysheridan.co.uk


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



RE: [PHP] Getting rid of extra lines

2009-07-29 Thread Bob McConnell
From: Miller, Terion

/* snip */

Before anyone can tell you how to fix it, you need to find out what is
causing that white space. is it empty lines, vertical tabs, thousands of
spaces, ...? Once you find that out, it is pretty easy to decide how to
get rid of them. Can you save the output to a file and open it with a
hex viewer?

Bob McConnell

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



Re: [PHP] preg_match too greedy

2009-07-29 Thread Ben Dunlap
Jim Lucas wrote:
 I expected 'no match' but get 'match'.
[8]
 cut/paste your code and it works for me.

Works for me as well. I get 'no match' from PHP 5.1.2, 5.2.6, and 5.2.8. What
version do you have?

If I might suggest a couple of simplifications that would make it easier to
follow/troubleshoot:

 $url = '/foo(/)?';

I don't think you need parentheses around your second forward-slash. If you had
multiple characters that were optional you'd want to group them in parentheses,
but here I think it just makes the regex harder to read.

 echo (preg_match($pattern, $test) != false)

The  != false  here is redundant. Combined with the ternary operator, the
logical switchbacks make me a little dizzy (especially this close to lunchtime).

Ben

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



[PHP] Asterisk anyone?

2009-07-29 Thread Skip Evans

Hey,

I've been asked to write a simple couple of public pages that 
would let an Asterisk customer modify their account 
configuration, but the client has no idea how Asterisk stores 
its data, apparently not in MySQL.


Anyone know of any resources for accessing Asterisk from PHP?

If anyone has done this can you tell me if I'm on the right 
track here?


http://www.voip-info.org/wiki/view/Asterisk+AGI+php#PHPTipsandExamples

--

Skip Evans
Big Sky Penguin, LLC
503 S Baldwin St, #1
Madison WI 53703
608.250.2720
http://bigskypenguin.com

Those of you who believe in
telekinesis, raise my hand.
 -- Kurt Vonnegut

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



Re: [PHP] preg_match too greedy

2009-07-29 Thread Jim Lucas
Ben Dunlap wrote:
 Jim Lucas wrote:
 I expected 'no match' but get 'match'.
 [8]
 cut/paste your code and it works for me.
 
 Works for me as well. I get 'no match' from PHP 5.1.2, 5.2.6, and 5.2.8. What
 version do you have?

PHP 5.2.5 with Suhosin-Patch 0.9.6.2 (cli) (built: Mar 11 2008 13:08:50)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
  with Suhosin v0.9.20, Copyright (c) 2002-2006, by Hardened-PHP Project


 
 If I might suggest a couple of simplifications that would make it easier to
 follow/troubleshoot:
 
 $url = '/foo(/)?';
 
 I don't think you need parentheses around your second forward-slash. If you 
 had
 multiple characters that were optional you'd want to group them in 
 parentheses,
 but here I think it just makes the regex harder to read.
 
 echo (preg_match($pattern, $test) != false)
 
 The  != false  here is redundant. Combined with the ternary operator, the
 logical switchbacks make me a little dizzy (especially this close to 
 lunchtime).
 
 Ben
 



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



Re: [PHP] Getting rid of extra lines

2009-07-29 Thread Jim Lucas
Miller, Terion wrote:
 I am trying to get rid of empty whitespace lines, I can't us chop() because
 as I read it it will remove all whitespacesright?
 
 Right now my db is outputting with extra lines, I have stripped tags I know
 it isn't that causing it to look like this
 
 Blahlajdlkfjlksdjflkdjsf
 
--how do I get rid of all this extra space?
 
 alkdfjlsdakjflsakdjflksjdf
 
 

If the white space is included in data coming from the db you could run
a simple little regex on the variable to removed any repetitive white
space.  But it might not be the best way to do it.

$clean = preg_replace('|\s+|', ' ', $input);
or
$clean = preg_replace('|\s{2,}|', ' ', $input);

If the white space is being generated in your HTML output, but is not in
your data store, then you need to cleanup your PHP code and that might help.


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



Re: [PHP] Getting rid of extra lines

2009-07-29 Thread Miller, Terion



On 7/29/09 1:45 PM, Ashley Sheridan a...@ashleysheridan.co.uk wrote:

[snip/]

Have you thought of just using a regular str_replace() on your code? You
can ask it to replace newlines and carriage returns with nothing and see
if that fixes you problem?

Thanks
Ash
www.ashleysheridan.co.uk



Yep I have tried str_replace to get rid of \n and it didn't work
Boss mentioned to explode the var that is full of so many blank lines then put 
it back together..seems like there has to be an easier way...

This is what I tried:

 $tags = array('\n', 'br');$sNotes = str_replace($tags,, $notes);

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



Re: [PHP] Getting rid of extra lines

2009-07-29 Thread Miller, Terion



On 7/29/09 2:19 PM, Jim Lucas li...@cmsws.com wrote:

$clean = preg_replace('|\s+|', ' ', $input);

Hi Jim,
The extra whitespace lines are in the data store, coming from it I'm going to 
try your method but is there a way to not have mySQL store it with so many 
lines (this is data being screen scraped and put in the db)
My code was at the beginning of this post of how I was inserting it.

Thanks
And Chocolate huh
Terion

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



Re: [PHP] Getting rid of extra lines

2009-07-29 Thread Jim Lucas
Miller, Terion wrote:
 
 
 On 7/29/09 2:19 PM, Jim Lucas li...@cmsws.com wrote:
 
 $clean = preg_replace('|\s+|', ' ', $input);
 
 Hi Jim,
 The extra whitespace lines are in the data store, coming from it I'm going to 
 try your method but is there a way to not have mySQL store it with so many 
 lines (this is data being screen scraped and put in the db)
 My code was at the beginning of this post of how I was inserting it.
 
 Thanks
 And Chocolate huh
 Terion
 

If the method that I give you works on the out from the db to the
browser, the should be no reason you cannot adapt whatever script you
are using for scrapping to use this function when it inserts the data
into the db.

Jim


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



Re: [PHP] Asterisk anyone?

2009-07-29 Thread Per Jessen
Skip Evans wrote:

 Hey,
 
 I've been asked to write a simple couple of public pages that
 would let an Asterisk customer modify their account
 configuration, but the client has no idea how Asterisk stores
 its data, apparently not in MySQL.

Depends on which data we're talking about.  Asterisk is very flexible.

 Anyone know of any resources for accessing Asterisk from PHP?
 
 If anyone has done this can you tell me if I'm on the right
 track here?
 
 http://www.voip-info.org/wiki/view/Asterisk+AGI+php#PHPTipsandExamples

That's definitely the right place to go, but it's not exactly enough to
asnwer your question. 

/Per

-- 
Per Jessen, Zürich (27.8°C)


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



Re: [PHP] Getting rid of extra lines

2009-07-29 Thread Jonathan Tapicer
On Wed, Jul 29, 2009 at 4:20 PM, Miller,
Teriontmil...@springfi.gannett.com wrote:



 On 7/29/09 1:45 PM, Ashley Sheridan a...@ashleysheridan.co.uk wrote:

 [snip/]

 Have you thought of just using a regular str_replace() on your code? You
 can ask it to replace newlines and carriage returns with nothing and see
 if that fixes you problem?

 Thanks
 Ash
 www.ashleysheridan.co.uk



 Yep I have tried str_replace to get rid of \n and it didn't work
 Boss mentioned to explode the var that is full of so many blank lines then 
 put it back together..seems like there has to be an easier way...

 This is what I tried:

     $tags = array('\n', 'br');    $sNotes = str_replace($tags,, $notes);

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



That didn't work because \n needs to be between   instead of ' '.

Jonathan

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



Re: [PHP] Getting rid of extra lines (RESOLVED)

2009-07-29 Thread Miller, Terion



On 7/29/09 3:05 PM, Jonathan Tapicer tapi...@gmail.com wrote:

On Wed, Jul 29, 2009 at 4:20 PM, Miller,
Teriontmil...@springfi.gannett.com wrote:



 On 7/29/09 1:45 PM, Ashley Sheridan a...@ashleysheridan.co.uk wrote:

 [snip/]

 Have you thought of just using a regular str_replace() on your code? You
 can ask it to replace newlines and carriage returns with nothing and see
 if that fixes you problem?

 Thanks
 Ash
 www.ashleysheridan.co.uk



 Yep I have tried str_replace to get rid of \n and it didn't work
 Boss mentioned to explode the var that is full of so many blank lines then 
 put it back together..seems like there has to be an easier way...

 This is what I tried:

 $tags = array('\n', 'br');$sNotes = str_replace($tags,, $notes);

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



That didn't work because \n needs to be between   instead of ' '.

Jonathan


Thanks Guys, ended up using Jim's way before inserting it into the db and it 
works like a charm


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



Re: [PHP] Getting rid of extra lines (RESOLVED)

2009-07-29 Thread Jim Lucas
Miller, Terion wrote:
 
 
 On 7/29/09 3:05 PM, Jonathan Tapicer tapi...@gmail.com wrote:
 
 On Wed, Jul 29, 2009 at 4:20 PM, Miller,
 Teriontmil...@springfi.gannett.com wrote:


 On 7/29/09 1:45 PM, Ashley Sheridan a...@ashleysheridan.co.uk wrote:

 [snip/]

 Have you thought of just using a regular str_replace() on your code? You
 can ask it to replace newlines and carriage returns with nothing and see
 if that fixes you problem?

 Thanks
 Ash
 www.ashleysheridan.co.uk



 Yep I have tried str_replace to get rid of \n and it didn't work
 Boss mentioned to explode the var that is full of so many blank lines then 
 put it back together..seems like there has to be an easier way...

 This is what I tried:

 $tags = array('\n', 'br');$sNotes = str_replace($tags,, $notes);

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


 
 That didn't work because \n needs to be between   instead of ' '.
 
 Jonathan
 
 
 Thanks Guys, ended up using Jim's way before inserting it into the db and it 
 works like a charm
 
 

Just to be clear.  Can you paste which one worked for you.


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



[PHP] Locating Bad Image Files

2009-07-29 Thread Floyd Resler
I use convert to create thumbnail images.  However, we have several  
PDFs that convert doesn't seem to like.  Even though it produced error  
messages it still creates the thumbnail which doesn't display an  
image.  Is there an easy way for me to identify those bad image files  
somehow in PHP by examining the content?


Thanks!
Floyd


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



Re: [PHP] Getting rid of extra lines (RESOLVED)

2009-07-29 Thread Miller, Terion



On 7/29/09 3:16 PM, Jim Lucas li...@cmsws.com wrote:

Miller, Terion wrote:


 On 7/29/09 3:05 PM, Jonathan Tapicer tapi...@gmail.com wrote:

 On Wed, Jul 29, 2009 at 4:20 PM, Miller,
 Teriontmil...@springfi.gannett.com wrote:


 On 7/29/09 1:45 PM, Ashley Sheridan a...@ashleysheridan.co.uk wrote:

 [snip/]

 Have you thought of just using a regular str_replace() on your code? You
 can ask it to replace newlines and carriage returns with nothing and see
 if that fixes you problem?

 Thanks
 Ash
 www.ashleysheridan.co.uk



 Yep I have tried str_replace to get rid of \n and it didn't work
 Boss mentioned to explode the var that is full of so many blank lines then 
 put it back together..seems like there has to be an easier way...

 This is what I tried:

 $tags = array('\n', 'br');$sNotes = str_replace($tags,, $notes);

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



 That didn't work because \n needs to be between   instead of ' '.

 Jonathan


 Thanks Guys, ended up using Jim's way before inserting it into the db and it 
 works like a charm



Just to be clear.  Can you paste which one worked for you.

This is what workedon my page that inserts the data to the db I put

 //stripping white line spaces$cleanNotes = preg_replace('|\s+|', ' ', 
$notes);$cleanVios = preg_replace('|\s+|', ' ', $cleanViolations);

then I mysql_escaped them and put them in the db, checked the csv and presto 
perfect no extra linespacing


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



[PHP] Expand Variables in String

2009-07-29 Thread Daniel Kolbo
Hello,

Is it possible to force a string to expand variable names after the
string has been set and before the variable's been defined without
having to do a string replace or preg_replace?

for example,
?php
$str = some string and some \$var plus other stuff;
echo $str.br /;
$var = Variable Contents;
echo $str.br /;
$str_expanded = $str;//would like this to expand $var into $str_expanded
echo $str_expanded.br /;
?

Thanks,
dK
`

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



Re: [PHP] Ridiculous ..won't print or echo ...(RESOLVED)

2009-07-29 Thread Miller, Terion

Yep I forgot about escaping the $



On 7/29/09 10:51 AM, Ford, Mike m.f...@leedsmet.ac.uk wrote:

 -Original Message-
 From: Miller, Terion [mailto:tmil...@springfi.gannett.com]
 Sent: 29 July 2009 16:36

 Ok in my output to Quark I need to have $P printed to the page like
 this:

 @$p2118 S. Campbell Ave

 So in my php which is going to be grabbing this info and formatting
 it for
 the Quarkisn't echoing that $p all I get is the @

 I have tried several things:

 $p = $p

 $p = print($p)

$p is trying to interpolate the value of the variable $p -- if you had full 
error reporting turned on, you would see a nonexistent variable error. Once 
more, there are several things you can do, of which the two most obvious are:

* Use single quotes: echo '$p';

* Use a backslash: echo \$p;


Cheers!

Mike
 --
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,
Leeds Metropolitan University, C507, Civic Quarter Campus,
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom
Email: m.f...@leedsmet.ac.uk
Tel: +44 113 812 4730





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

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




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



[PHP] Page or URL function?

2009-07-29 Thread Miller, Terion
I've been searching php.net for a function to do this:

   if page_url('browse.php') {

$default = A;

  }

$letter = isset($_GET['letter'])? $_GET['letter'] :$default ;

else
 {

$letter = isset($_GET['letter'])? $_GET['letter'] : ;

}

I want to say if the page is browse, default to the A listings, if the page
is not browse show no default listings (because there is other data on the
page and I don't want this to output)

I thought there was url functionsam I calling it something different?
Terion


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



Re: [PHP] Expand Variables in String

2009-07-29 Thread Jonathan Tapicer
Use eval, like this:

eval('$str_expanded = ' . str_replace('', '\\', $str) . ';');

The str_replace is used because you could have a  inside $str and it
would break the string, if you are sure the $str has no  inside you
can omit it.

Jonathan

On Wed, Jul 29, 2009 at 5:43 PM, Daniel Kolbokolb0...@umn.edu wrote:
 Hello,

 Is it possible to force a string to expand variable names after the
 string has been set and before the variable's been defined without
 having to do a string replace or preg_replace?

 for example,
 ?php
 $str = some string and some \$var plus other stuff;
 echo $str.br /;
 $var = Variable Contents;
 echo $str.br /;
 $str_expanded = $str;//would like this to expand $var into $str_expanded
 echo $str_expanded.br /;
 ?

 Thanks,
 dK
 `

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



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



[PHP] fileinfo returning wrong mime type for Excel files

2009-07-29 Thread Christoph Boget
Consider the following:

$finfo = finfo_open( FILEINFO_MIME, '/usr/share/file/magic' );
if( $finfo )
{
  $mimeType = finfo_file( $finfo, '/path/to/my/excel.xls' );
  finfo_close($finfo);
}
echo $mimeType;

When I run the above, it echoes out application/msword.  Why?  I
understand that both excel and word are part of the office suite but
why isn't it returning application/excel as it should?  As far as I
can tell, we're using the most up to date version of fileinfo for PHP
5.2.5.  Is there something else I'm missing?  Or doing wrong?

thnx,
Christoph

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



[PHP] Re: Page or URL function?

2009-07-29 Thread Ben Dunlap
 I've been searching php.net for a function to do this:
 
if page_url('browse.php') {

The $_SERVER global array has this sort of information. The 'PHP_SELF' key
might be what you want:

http://us.php.net/manual/en/reserved.variables.server.php

But where is the code that needs to know? I'm guessing it's in a common library
file that's going to be included in browse.php as well as other scripts, but am
I guessing rightly?

BTW, you could simplify your code slightly by defining $default as an empty
string before the IF block. Then you only have to read from $_GET once.

?php
$default = ;
if (url condition) {
   $default = A;
}
/*
 * No need for an else any more, now you can just
 * set the value of $letter
 */
?

I'd also suggest using filter_input() rather than reading directly from $_GET:

?php
$letter = filter_input(INPUT_GET, 'letter', filter, [options]);
if (empty($letter)) {
$letter = $default;
}
?

Presumably you'd want to use FILTER_VALIDATE_REGEXP in place of filter and,
for options, pass a regex that ensures that 'letter' is a single
alphabetical character.

You can read about the filter functions here (sort of, the documentation is a
little sparse):

http://us.php.net/manual/en/ref.filter.php

A VALIDATE_REGEXP example is available here:

http://www.w3schools.com/php/filter_validate_regexp.asp

Ben

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



[PHP] Re: Page or URL function?

2009-07-29 Thread Ben Dunlap
Ben Dunlap wrote [TWICE]:
 The $_SERVER global array has this sort of information. The 'PHP_SELF' key
[8]
 Ben

Very sorry for the double-post. Reply-all in Thunderbird News seems a little
overzealous by default.

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



Re: [PHP] Asterisk anyone?

2009-07-29 Thread Skip Evans

Per Jessen wrote:

Depends on which data we're talking about.  Asterisk is very flexible.



For example, the first screen they want people to be able to 
change data on is:


call waiting,do not disturb
and then it looks like numbers (forwarding?)
unconditional,unavailable,busy

I'm trying to figure out now are these values stored in a 
regular relational database like MySQL.


But so far the documentation I see is really all about how to 
handle calls, not manage customer data.


--

Skip Evans
Big Sky Penguin, LLC
503 S Baldwin St, #1
Madison WI 53703
608.250.2720
http://bigskypenguin.com

Those of you who believe in
telekinesis, raise my hand.
 -- Kurt Vonnegut

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



Re: [PHP] Expand Variables in String

2009-07-29 Thread Daniel Kolbo
Jonathan Tapicer wrote:
 Use eval, like this:
 
 eval('$str_expanded = ' . str_replace('', '\\', $str) . ';');
 
 The str_replace is used because you could have a  inside $str and it
 would break the string, if you are sure the $str has no  inside you
 can omit it.
 
 Jonathan
 
 On Wed, Jul 29, 2009 at 5:43 PM, Daniel Kolbokolb0...@umn.edu wrote:
 Hello,

 Is it possible to force a string to expand variable names after the
 string has been set and before the variable's been defined without
 having to do a string replace or preg_replace?

 for example,
 ?php
 $str = some string and some \$var plus other stuff;
 echo $str.br /;
 $var = Variable Contents;
 echo $str.br /;
 $str_expanded = $str;//would like this to expand $var into $str_expanded
 echo $str_expanded.br /;
 ?

 Thanks,
 dK
 `

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


 
nice!

This would allow me to have $str loaded with all kinds of variables and
not have to do a str_replace with each (assuming the quote business is cool)

Why did you have the double \\?
 eval('$str_expanded = ' . str_replace('', '\\', $str) . ';');
Isn't the following equivalent?
eval('$str_expanded = ' . str_replace('', '\', $str) . ';');

Thanks,
dK
`

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



Re: [PHP] Expand Variables in String

2009-07-29 Thread Jonathan Tapicer
On Wed, Jul 29, 2009 at 6:47 PM, Daniel Kolbokolb0...@umn.edu wrote:
 Jonathan Tapicer wrote:
 Use eval, like this:

 eval('$str_expanded = ' . str_replace('', '\\', $str) . ';');

 The str_replace is used because you could have a  inside $str and it
 would break the string, if you are sure the $str has no  inside you
 can omit it.

 Jonathan

 On Wed, Jul 29, 2009 at 5:43 PM, Daniel Kolbokolb0...@umn.edu wrote:
 Hello,

 Is it possible to force a string to expand variable names after the
 string has been set and before the variable's been defined without
 having to do a string replace or preg_replace?

 for example,
 ?php
 $str = some string and some \$var plus other stuff;
 echo $str.br /;
 $var = Variable Contents;
 echo $str.br /;
 $str_expanded = $str;//would like this to expand $var into $str_expanded
 echo $str_expanded.br /;
 ?

 Thanks,
 dK
 `

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



 nice!

 This would allow me to have $str loaded with all kinds of variables and
 not have to do a str_replace with each (assuming the quote business is cool)

 Why did you have the double \\?
 eval('$str_expanded = ' . str_replace('', '\\', $str) . ';');
 Isn't the following equivalent?
 eval('$str_expanded = ' . str_replace('', '\', $str) . ';');

 Thanks,
 dK
 `


Yes, it's the same, you can use only one \ in that case, sometimes you
have to escape if it is followed by a character that needs to be
escaped, for example you can't do echo '\'; you should do echo '\\';

Jonathan

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



[PHP] Re: preg_match too greedy

2009-07-29 Thread Clancy
On Wed, 29 Jul 2009 13:42:23 -0400, p...@logi.ca (b) wrote:

I'm trying to figure out how to test if a string matches *exactly* 
another string, using a regexp pattern. 

If this is REALLY what you want to do, what is wrong with strcmp?


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



Re: [PHP] preg_match too greedy

2009-07-29 Thread Daniel Kolbo
Jim Lucas wrote:
 Ben Dunlap wrote:
 Jim Lucas wrote:
 I expected 'no match' but get 'match'.
 [8]
 cut/paste your code and it works for me.
 Works for me as well. I get 'no match' from PHP 5.1.2, 5.2.6, and 5.2.8. What
 version do you have?
 
 PHP 5.2.5 with Suhosin-Patch 0.9.6.2 (cli) (built: Mar 11 2008 13:08:50)
 Copyright (c) 1997-2007 The PHP Group
 Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
   with Suhosin v0.9.20, Copyright (c) 2002-2006, by Hardened-PHP Project
 
 
 If I might suggest a couple of simplifications that would make it easier to
 follow/troubleshoot:

 $url = '/foo(/)?';
 I don't think you need parentheses around your second forward-slash. If you 
 had
 multiple characters that were optional you'd want to group them in 
 parentheses,
 but here I think it just makes the regex harder to read.

 echo (preg_match($pattern, $test) != false)
 The  != false  here is redundant. Combined with the ternary operator, the
 logical switchbacks make me a little dizzy (especially this close to 
 lunchtime).

 Ben

 
 
 
code works (no match) for me too on php 5.2.6 build date May 2 2008
18:01:20 with dumbdows NT.

preg_match fails but for a reason other than what I think you may be
expecting.  It fails b/c of the first forwards slash in $url.  The regex
engine doesn't even get past the second character let alone reaching the
end of line anchor.

Also, your code works (no match) with this first forward slash removed:
$url = 'foo(/)?'
This time preg_match fails due to the end of line anchor.
hth
dK
`

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



Re: [PHP] preg_match too greedy

2009-07-29 Thread b

On 07/29/2009 02:07 PM, Jim Lucas wrote:

b wrote:

I'm trying to figure out how to test if a string matches *exactly*
another string, using a regexp pattern. The manual says that ereg() is
deprecated (in favour of what?) and preg_match() is giving me trouble.
The problem is that I'm passing the end-of-line delimiter ($) but it
seems to be ignored. An example:

-- snip --
header('Content-type: text/plain');
$url = '/foo(/)?';
$test = 'foo/bar';
$pattern = '%^'.$url.'$%U';

echo ${url} :: ${test}\n;

echo (preg_match($pattern, $test) != false)
 ? 'match'
 : 'no match';
-- snip --

I expected 'no match' but get 'match'.

The reason for the (/)? is to allow for a trailing slash. I've added a
'$' to specify that I want to test for the exact string. However,
preg_match() tests for the existence of a string and appears to ignore
the '$'.

How do I do this?



cut/paste your code and it works for me.

Jim Lucas



Works, meaning you get 'match', or 'no match'? It should be the latter, 
but I'm seeing the former.


I'm using 5.2.9, btw.

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



Re: [PHP] preg_match too greedy

2009-07-29 Thread b

On 07/29/2009 03:03 PM, Ben Dunlap wrote:

Jim Lucas wrote:

I expected 'no match' but get 'match'.

[8]

cut/paste your code and it works for me.


Works for me as well. I get 'no match' from PHP 5.1.2, 5.2.6, and 5.2.8. What
version do you have?


5.2.9


If I might suggest a couple of simplifications that would make it easier to
follow/troubleshoot:


$url = '/foo(/)?';


I don't think you need parentheses around your second forward-slash. If you had
multiple characters that were optional you'd want to group them in parentheses,
but here I think it just makes the regex harder to read.


Really? I think it makes it crystal clear that it's the '/' that is 
optional. In any case, it makes no difference.





echo (preg_match($pattern, $test) != false)


The  != false  here is redundant.


Understood. But what you think is redundancy is, to me, clarity in 
programming. I happen to think that boolean tests shouldn't ride on 
whether or not an array returned from a function is empty or not (or a 
freaking boolean). If what I'm looking for is a false then that's what 
I'll test for.



Combined with the ternary operator, the logical switchbacks make me a

 little dizzy (especially this close to lunchtime).




Oh, you're one of those people who can't stand the sight of a ternary 
operator. Buck up, son, it's good for ya ;-)


(Seriously: I don't understand why ternaries freak some people out. It's 
plain as day!)



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



Re: [PHP] preg_match too greedy

2009-07-29 Thread b

On 07/29/2009 07:48 PM, Daniel Kolbo wrote:


code works (no match) for me too on php 5.2.6 build date May 2 2008
18:01:20 with dumbdows NT.

preg_match fails but for a reason other than what I think you may be
expecting.  It fails b/c of the first forwards slash in $url.  The regex
engine doesn't even get past the second character let alone reaching the
end of line anchor.


The forward slash shouldn't be an issue as the delimiter is '%'. The 
full pattern is:


%^/foo/?$%U



Also, your code works (no match) with this first forward slash removed:
$url = 'foo(/)?'


But the string happens to start with a forward slash.


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



Re: [PHP] fileinfo returning wrong mime type for Excel files

2009-07-29 Thread Paul M Foster
On Wed, Jul 29, 2009 at 05:15:38PM -0400, Christoph Boget wrote:

 Consider the following:
 
 $finfo = finfo_open( FILEINFO_MIME, '/usr/share/file/magic' );
 if( $finfo )
 {
   $mimeType = finfo_file( $finfo, '/path/to/my/excel.xls' );
   finfo_close($finfo);
 }
 echo $mimeType;
 
 When I run the above, it echoes out application/msword.  Why?  I
 understand that both excel and word are part of the office suite but
 why isn't it returning application/excel as it should?  As far as I
 can tell, we're using the most up to date version of fileinfo for PHP
 5.2.5.  Is there something else I'm missing?  Or doing wrong?
 
 thnx,
 Christoph

Presumably, this information comes directly from /usr/share/file/magic.
FWIW, my copy of this file is in /usr/share/misc/file/magic, which is
where the man page says it should be. Debian Linux v5.

Paul

-- 
Paul M. Foster

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



Re: [PHP] preg_match too greedy

2009-07-29 Thread Daniel Kolbo
b wrote:
 On 07/29/2009 07:48 PM, Daniel Kolbo wrote:

 code works (no match) for me too on php 5.2.6 build date May 2 2008
 18:01:20 with dumbdows NT.

 preg_match fails but for a reason other than what I think you may be
 expecting.  It fails b/c of the first forwards slash in $url.  The regex
 engine doesn't even get past the second character let alone reaching the
 end of line anchor.
 
 The forward slash shouldn't be an issue as the delimiter is '%'. The
 full pattern is:
 
 %^/foo/?$%U
 
 
 Also, your code works (no match) with this first forward slash removed:
 $url = 'foo(/)?'
 
 But the string happens to start with a forward slash.
 
 
i am not talking about the delimiter
your pattern is:
%^/foo/?$%U
your test string is:
'foo/bar'

the first character of your pattern is a / and your first character of
your test string is an f.  They do not match.  The regex engine stops
after checking the first character.  This has nothing to do with
greediness or end of line anchors, but only with the first character
comparisons.

maybe what you wanted for your test string was
'/foo/bar'

This test string would then require your end of line anchor. Because the
end of line character does not match the b the engine stops.  No match.

This is consistent with the findings of others who replied to you.

Perhaps your regex engine has a different syntax for anchors.  For
example if your engine was seeing the carrot as a an exclusion operator
rather than being a beginning of line anchor and it was also, idk,
ignoring the dollar sign as your end of line anchor then you would get a
match.  But otherwise I would recommend you copy/paste the example you
provided and confirm that you still get a match.  Then i would confirm
your regex engine's anchor syntax.  Then, recompile your software
dK
`

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



Re: [PHP] preg_match too greedy

2009-07-29 Thread b

On 07/29/2009 11:18 PM, Daniel Kolbo wrote:

b wrote:

On 07/29/2009 07:48 PM, Daniel Kolbo wrote:

code works (no match) for me too on php 5.2.6 build date May 2 2008
18:01:20 with dumbdows NT.

preg_match fails but for a reason other than what I think you may be
expecting.  It fails b/c of the first forwards slash in $url.  The regex
engine doesn't even get past the second character let alone reaching the
end of line anchor.

The forward slash shouldn't be an issue as the delimiter is '%'. The
full pattern is:

%^/foo/?$%U



Also, your code works (no match) with this first forward slash removed:
$url = 'foo(/)?'

But the string happens to start with a forward slash.



i am not talking about the delimiter
your pattern is:
%^/foo/?$%U
your test string is:
'foo/bar'


AAARRRGG! Sorry, that's a typo! It should be:

$test = '/foo/bar';

I guess that explains a lot. For the record, I had to type that in 
because this latest version of Thunderbird crashes whenever I paste into 
it. (note to self: downgrade that, stat!)






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