php-general Digest 29 Jul 2009 18:40:02 -0000 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


----------------------------------------------------------------------
--- Begin Message ---
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 ---
--- Begin Message ---
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=2031&highlight=>

<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 ---
--- Begin Message ---
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 893333
Developer                               fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

--- End Message ---
--- Begin Message ---
>> $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 ---
--- Begin Message ---
> -----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

--- End Message ---
--- Begin Message ---
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

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


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.........

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

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


--- End Message ---
--- Begin Message ---
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,
Terion<tmil...@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 0000-00-00 like sql stores it because I ran it with the 
> unix stamp and it just stored 000000 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 morning....but 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_modify....I'm
> lost...
>
> My full code is this:
>
> preg_match_all('/<p><font 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 <br><hr>";
>
>
>
> --
> 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
YYYY/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/yyyy 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


--- End Message ---
--- Begin Message ---
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


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

<@$p>2118 S. Campbell Ave

So in my php which is going to be grabbing this info and formatting it for
the Quark....isn'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...


--- End Message ---
--- Begin Message ---
>Ok in my output to Quark I need to have $P printed to the page like this:
>
><@$p>2118 S. Campbell Ave
>
>So in my php which is going to be grabbing this info and formatting it for
>the Quark....isn'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.


--- End Message ---
--- Begin Message ---
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:
> 
> <@$p>2118 S. Campbell Ave
> 
> So in my php which is going to be grabbing this info and formatting it for
> the Quark....isn'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


--- End Message ---
--- Begin Message ---
> -----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:
> 
> <@$p>2118 S. Campbell Ave
> 
> So in my php which is going to be grabbing this info and formatting
> it for
> the Quark....isn'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

--- End Message ---
--- Begin Message ---
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:
>
> <@$p>2118 S. Campbell Ave
>
> So in my php which is going to be grabbing this info and formatting it for
> the Quark....isn'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




--- End Message ---
--- Begin Message --- 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?

--- End Message ---
--- Begin Message ---
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


--- End Message ---
--- Begin Message ---
I am trying to get rid of empty whitespace lines, I can't us chop() because
as I read it it will remove all whitespaces....right?

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


--- End Message ---
--- Begin Message ---
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 whitespaces....right?
> 
> 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


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


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 whitespaces....right?
>
> 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); }             /**/ };





--- End Message ---

Reply via email to