FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » String Question
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
String Question [message #172796] Wed, 02 March 2011 20:38 Go to next message
Patrick[1] is currently offline  Patrick[1]
Messages: 2
Registered: March 2011
Karma: 0
Junior Member
Don't usually frequent this news group, but I have a stumper. At least
it is stumping me.

I have one variable that I have assigned a string value to;
(verbatum from my code)

$errval = 'ERROR: duplicate key violates unique constraint
"machines2_pkey"';

and another variable that I assign a value from a command;

$pglerr = pg_last_error();

The value being: ERROR: duplicate key violates unique constraint
"machines2_pkey"

yet when I do a strlen $errval is 64 and $pglerr is 65.

What am I missing here? I've tried trim() on the latter and still get 65.

If someone could shine some light on this for me I would appreciate it.

Thanks

--
Patrick A. Smith Assistant System Administrator
Ocean Circulation Group – USF - College of Marine Science
http://ocgweb.marine.usf.edu

The trouble with doing something right the first time is that nobody
appreciates how difficult it was. - La Rochefoucauld
Re: String Question [message #172797 is a reply to message #172796] Wed, 02 March 2011 20:59 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On 02/03/11 20:38, Patrick wrote:

> yet when I do a strlen $errval is 64 and $pglerr is 65.

Have a more detailed look at the string contents, maybe looking at eg
the ascii codes for each char in the string. function strbits below
might help:

<?php

function strbits($str) {
$i = strlen($str);
$a = array();
while (--$i) $a[$i] = ord(substr($str,$i,1));
return $a;
}

?>

Rgds

Denis McMahon
Re: String Question [message #172798 is a reply to message #172797] Wed, 02 March 2011 21:14 Go to previous messageGo to next message
Patrick[1] is currently offline  Patrick[1]
Messages: 2
Registered: March 2011
Karma: 0
Junior Member
On 3/2/2011 3:59 PM, Denis McMahon wrote:
> On 02/03/11 20:38, Patrick wrote:
>
>> yet when I do a strlen $errval is 64 and $pglerr is 65.
>
> Have a more detailed look at the string contents, maybe looking at eg
> the ascii codes for each char in the string. function strbits below
> might help:
>
> <?php
>
> function strbits($str) {
> $i = strlen($str);
> $a = array();
> while (--$i) $a[$i] = ord(substr($str,$i,1));
> return $a;
> }
>
> ?>
>
> Rgds
>
> Denis McMahon

Thanks. I came to that same conclusion and found that there are 2 spaces
between "ERROR:" and "duplicate" in the second string and only one in
the first. No way you could ever tell that from the output on the screen.

Patrick
Re: String Question [message #172799 is a reply to message #172798] Wed, 02 March 2011 21:25 Go to previous messageGo to next message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma: 0
Senior Member
.oO(Patrick)

> Thanks. I came to that same conclusion and found that there are 2 spaces
> between "ERROR:" and "duplicate" in the second string and only one in
> the first. No way you could ever tell that from the output on the screen.

Of course there are: In cases like this never look at the rendered HTML
output, but at the source code. Or send a 'Content-Type: text/plain'
header, so the browser will not interpret the received data as HTML.

Micha
Re: String Question [message #172800 is a reply to message #172799] Wed, 02 March 2011 21:27 Go to previous messageGo to next message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma: 0
Senior Member
.oO(Michael Fesser)

> .oO(Patrick)
>
>> Thanks. I came to that same conclusion and found that there are 2 spaces
>> between "ERROR:" and "duplicate" in the second string and only one in
>> the first. No way you could ever tell that from the output on the screen.
>
> Of course there are: In cases like this never look at the rendered HTML
> output, but at the source code. Or send a 'Content-Type: text/plain'
> header, so the browser will not interpret the received data as HTML.

Forgot one: Wrap your string in '<pre>…</pre>' tags, so the browser will
render it as plain text and not collapse whitespace like HTML does.

Micha
Re: String Question [message #172801 is a reply to message #172798] Wed, 02 March 2011 21:56 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On 02/03/11 21:14, Patrick wrote:
> On 3/2/2011 3:59 PM, Denis McMahon wrote:
>> On 02/03/11 20:38, Patrick wrote:
>>
>>> yet when I do a strlen $errval is 64 and $pglerr is 65.
>>
>> Have a more detailed look at the string contents, maybe looking at eg
>> the ascii codes for each char in the string. function strbits below
>> might help:
>>
>> <?php
>>
>> function strbits($str) {
>> $i = strlen($str);
>> $a = array();
>> while (--$i) $a[$i] = ord(substr($str,$i,1));
>> return $a;
>> }
>>
>> ?>
>>
>> Rgds
>>
>> Denis McMahon
>
> Thanks. I came to that same conclusion and found that there are 2 spaces
> between "ERROR:" and "duplicate" in the second string and only one in
> the first. No way you could ever tell that from the output on the screen.

Ah, you were viewing the error message in a browser and then pasting it
into text? Browsers do things like 's/\s*/ /'

Rgds

Denis McMahon
Re: String Question [message #172807 is a reply to message #172801] Thu, 03 March 2011 07:32 Go to previous messageGo to next message
Curtis Dyer is currently offline  Curtis Dyer
Messages: 34
Registered: January 2011
Karma: 0
Member
Denis McMahon <denis(dot)m(dot)f(dot)mcmahon(at)googlemail(dot)com> wrote:

> On 02/03/11 21:14, Patrick wrote:
>> On 3/2/2011 3:59 PM, Denis McMahon wrote:
>>> On 02/03/11 20:38, Patrick wrote:

<snip>

>> Thanks. I came to that same conclusion and found that there are
>> 2 spaces between "ERROR:" and "duplicate" in the second string
>> and only one in the first. No way you could ever tell that from
>> the output on the screen.
>
> Ah, you were viewing the error message in a browser and then
> pasting it into text? Browsers do things like 's/\s*/ /'

Did you mean:

s/\s+/ /

Your regex would replace "foo" with " f o o ".

--
Curtis Dyer
<?$x='<?$x=%c%s%c;printf($x,39,$x,39);?>';printf($x,39,$x,39);?>
Re: String Question [message #172813 is a reply to message #172807] Thu, 03 March 2011 18:59 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On 03/03/11 07:32, Curtis Dyer wrote:
> Denis McMahon <denis(dot)m(dot)f(dot)mcmahon(at)googlemail(dot)com> wrote:
>
>> On 02/03/11 21:14, Patrick wrote:
>>> On 3/2/2011 3:59 PM, Denis McMahon wrote:
>>>> On 02/03/11 20:38, Patrick wrote:
>
> <snip>
>
>>> Thanks. I came to that same conclusion and found that there are
>>> 2 spaces between "ERROR:" and "duplicate" in the second string
>>> and only one in the first. No way you could ever tell that from
>>> the output on the screen.
>>
>> Ah, you were viewing the error message in a browser and then
>> pasting it into text? Browsers do things like 's/\s*/ /'
>
> Did you mean:
>
> s/\s+/ /
>
> Your regex would replace "foo" with " f o o ".

Probably. I should wake up before posting regexes heh.

Rgds

Denis McMahon
Re: String Question [message #172814 is a reply to message #172813] Thu, 03 March 2011 19:17 Go to previous message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
Denis McMahon wrote:
> On 03/03/11 07:32, Curtis Dyer wrote:
>> Denis McMahon <denis(dot)m(dot)f(dot)mcmahon(at)googlemail(dot)com> wrote:
>>
>>> On 02/03/11 21:14, Patrick wrote:
>>>> On 3/2/2011 3:59 PM, Denis McMahon wrote:
>>>> > On 02/03/11 20:38, Patrick wrote:
>> <snip>
>>
>>>> Thanks. I came to that same conclusion and found that there are
>>>> 2 spaces between "ERROR:" and "duplicate" in the second string
>>>> and only one in the first. No way you could ever tell that from
>>>> the output on the screen.
>>> Ah, you were viewing the error message in a browser and then
>>> pasting it into text? Browsers do things like 's/\s*/ /'
>> Did you mean:
>>
>> s/\s+/ /
>>
>> Your regex would replace "foo" with " f o o ".
>
> Probably. I should wake up before posting regexes heh.
>

Another reason why I would prefer to learn Linear B, than Regexps. It
tends to be slightly easier.

> Rgds
>
> Denis McMahon
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: genuine adsence accounts Big offer
Next Topic: fgetcsv -- No error reporting?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 15:55:19 GMT 2024

Total time taken to generate the page: 0.02309 seconds