php-general Digest 23 Dec 2012 03:29:11 -0000 Issue 8074

Topics (messages 319936 through 319946):

Re: Strange string stuff -- maybe everything is ending...
        319936 by: tamouse mailing lists
        319938 by: Tedd Sperling
        319940 by: Jim Giner
        319941 by: Tedd Sperling
        319942 by: Tedd Sperling
        319943 by: Tedd Sperling
        319944 by: Tim Streater
        319945 by: Bastien
        319946 by: Stefan Wixfort

[ad] [free+opensource] htmlMicroscope (nested array viewer/dumper) upgraded - 
now allows for even larger arrays
        319937 by: rene7705

A Recent Emacs Mode for PHP
        319939 by: Eric James Michael Ritz

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 Fri, Dec 21, 2012 at 7:06 PM, Jim Giner <jim.gi...@albanyhandball.com> wrote:
> That actually makes sense tho.  Afterall, a string is truly only one memory
> allocation whereas array elements are basically multiple vars having the
> same name.  So - how can you unset one char in a string?

That actually depends on what you mean by "unset". If you mean to
remove it, str_replace should do, or if you only know it's position,
using substr twice to grab the front and back should work.

Setting a charcter to null ('') in the middle of the string could be
interesting for some applications...


Following up with the example I just showed:

// now let's 'unset' a character in the middle
$s3 = $s;
$s3[10] = '';
showstring($s3);

yields:

String of length 34 is Now we aregone down to the river!
s[0] : 'N' 78 s[1] : 'o' 111 s[2] : 'w' 119 s[3] : ' ' 32 s[4] : 'w'
119 s[5] : 'e' 101 s[6] : ' ' 32 s[7] : 'a' 97 s[8] : 'r' 114 s[9] :
'e' 101 s[10] : '' 0 s[11] : 'g' 103 s[12] : 'o' 111 s[13] : 'n' 110
s[14] : 'e' 101 s[15] : ' ' 32 s[16] : 'd' 100 s[17] : 'o' 111 s[18] :
'w' 119 s[19] : 'n' 110 s[20] : ' ' 32 s[21] : 't' 116 s[22] : 'o' 111
s[23] : ' ' 32 s[24] : 't' 116 s[25] : 'h' 104 s[26] : 'e' 101 s[27] :
' ' 32 s[28] : 'r' 114 s[29] : 'i' 105 s[30] : 'v' 118 s[31] : 'e' 101
s[32] : 'r' 114 s[33] : '!' 33


Still 34 byte string length, but looking at s[10] you see the null
byte. It didn't really affect printing, but it might affect other
things.

--- End Message ---
--- Begin Message ---
On Dec 21, 2012, at 5:20 PM, Volmar Machado <qi.vol...@gmail.com> wrote:

> What is the result in FF? And on IE? (the echoed string)

That's the problem, it's different.

If the last char in a string is set to null, then it causes JavaScript routines 
running under IE to behave differently than the exact same JavaScript routines 
running under Safari or FireFox. This was something I never expected.

However, the web industry has had to deal with IE oddities for many, many years 
-- the problem remains and it's called IE.

Remember, M$ always has a better idea.

Cheers,

tedd


_____________________
t...@sperling.com
http://sperling.com





--- End Message ---
--- Begin Message ---
On 12/22/2012 11:29 AM, Tedd Sperling wrote:
On Dec 21, 2012, at 5:20 PM, Volmar Machado <qi.vol...@gmail.com> wrote:

What is the result in FF? And on IE? (the echoed string)

That's the problem, it's different.

If the last char in a string is set to null, then it causes JavaScript routines 
running under IE to behave differently than the exact same JavaScript routines 
running under Safari or FireFox. This was something I never expected.

However, the web industry has had to deal with IE oddities for many, many years 
-- the problem remains and it's called IE.

Remember, M$ always has a better idea.

Cheers,

tedd


_____________________
t...@sperling.com
http://sperling.com




But basically, I think the work that others have done shows you that your use of indices on strings is not the best way to manipulate them. Hey - it's a string - use substr. :)
--- End Message ---
--- Begin Message ---
On Dec 21, 2012, at 5:27 PM, Jim Giner <jim.gi...@albanyhandball.com> wrote:
> From what I do know, there shouldn't be an a[4].
> In any case, let's assume that there is a bug in the string logic that you're 
> using.  Why not just use substr?
> 
> $topic = substr($topic,0,-1);

and

On Dec 21, 2012, at 6:10 PM, Nathan Nobbe <quickshif...@gmail.com> wrote:
> Neat idea Tedd, but judging by a quick test, I don't think changing the
> value of the string is entirely supported though that notation.
> 
> php > $str = 'blah';
> php > $str[3] = '';
> php > echo $str . PHP_EOL;
> bla
> php > echo strlen($str);
> 4


I'm not looking for a solution, but rather pointing out something I never 
encountered before.

I would have never thought that a string echoed by a PHP script to be used in a 
JavaScript routine would depend upon what Browser it is run on. That seems odd.

Cheers,

tedd


_____________________
t...@sperling.com
http://sperling.com




--- End Message ---
--- Begin Message ---
On Dec 21, 2012, at 8:06 PM, Jim Giner <jim.gi...@albanyhandball.com> wrote:
>> That actually makes sense tho.  Afterall, a string is truly only one memory 
>> allocation whereas array elements are basically multiple vars having the 
>> same name.  So - how can you unset one char in a string?

It depends upon the language -- while it is true that the start of a string is 
located at a memory address, the chars of the string are identical to the chars 
in an array. As such, you can view a string as an array. Each index is 
representative of a char (one byte) in the string.

Cheers,

tedd


_____________________
t...@sperling.com
http://sperling.com





--- End Message ---
--- Begin Message ---
On Dec 22, 2012, at 7:58 AM, tamouse mailing lists <tamouse.li...@gmail.com> 
wrote:

> A bit of an example to shed a little light?
> -snip-
> Not knowing IE really at all, nor it's JS engine, it's entirely
> possible that a null character in a string causes it to have problems.

That's the explanation I was looking for -- thanks!

Cheers,

tedd

_____________________
t...@sperling.com
http://sperling.com

--- End Message ---
--- Begin Message ---
On 22 Dec 2012 at 16:50, Tedd Sperling <t...@sperling.com> wrote: 

> On Dec 21, 2012, at 8:06 PM, Jim Giner <jim.gi...@albanyhandball.com> wrote:
>>> That actually makes sense tho.  Afterall, a string is truly only one memory
>>> allocation whereas array elements are basically multiple vars having the
>>> same name.  So - how can you unset one char in a string?
>
> It depends upon the language -- while it is true that the start of a string is
> located at a memory address, the chars of the string are identical to the
> chars in an array. As such, you can view a string as an array. Each index is
> representative of a char (one byte) in the string.

That is explicitly documented here:

<http://php.net/manual/en/language.types.string.php>

String access and modification by character

Characters within strings may be accessed and modified by specifying the 
zero-based offset of the desired character after the string using square array 
brackets, as in $str[42]. Think of a string as an array of characters for this 
purpose. The functions substr() and substr_replace() can be used when you want 
to extract or replace more than 1 character.

--
Cheers  --  Tim

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

Bastien Koert

On 2012-12-22, at 11:50 AM, Tedd Sperling <t...@sperling.com> wrote:

> On Dec 22, 2012, at 7:58 AM, tamouse mailing lists <tamouse.li...@gmail.com> 
> wrote:
> 
>> A bit of an example to shed a little light?
>> -snip-
>> Not knowing IE really at all, nor it's JS engine, it's entirely
>> possible that a null character in a string causes it to have problems.
> 
> That's the explanation I was looking for -- thanks!
> 


You'll need to check various versions of IE. IE8 has significant JS speed and 
performance issues that don't show up in v7 or v9.

God bless Internet Exploder





> Cheers,
> 
> tedd
> 
> _____________________
> t...@sperling.com
> http://sperling.com
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

--- End Message ---
--- Begin Message ---
On 22.12.2012 00:31, Bastien wrote:

On 2012-12-21, at 5:05 PM, Ken Robinson <kenrb...@rbnsn.com> wrote:

A much easier way to do this would be to use a temporary array and then explode:

$tmp = array();
        while($row = mysql_fetch_array($result)) // pulling stuff from a 
database
                {
                $tmp[] = $row['category'];
                }

            $topic = explode('~',$tmp); // put the delimiter between each entry
        echo($topic);   // this result is used in an AJAX script



Shouldn't that be implode to convert the array to string with the delimiter?


Bastien


Yes, it should be implode().

Stefan

--- End Message ---
--- Begin Message ---
Hi Folks.

URL: http://fancywebapps.com/products/htmlMicroscope

Just wanted to let you all know that I've completed a long overdue
upgrade to my free htmlMicroscope web component.
It is basically a fancy replacement for var_dump() which can show you
the full depth of an array regardless of how large or deep your PHP
array or javascript object is.

I won't repeat the entire homepage content here, but I think this
version could be useful for at least some of the programmers on this
list.

I'll only repeat this message for significant updates.

This is a significant update because I've finally cracked the barrier
of displaying an object with more than a few hundred key-value pairs
on a single level. That used to crash all browsers, not anymore.

i'll continue work on this, want to build in (in order of priority):
- auto navigation options (auto smooth scroll to links within the data)
- middle mouse button click -> smooth offset scrolling
- html source view
- auto indented and colorcoded syntax-checked view for html + json

Merry Christmas and a productive New Year to ya'll :D

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

I do not know how many PHP developers use GNU Emacs for writing code.
But I assume it must be a decent amount since there are multiple PHP
modes for Emacs floating around the Internet.  For months I have
worked to improve one of those modes, what seemed to be the most
popular: http://php-mode.sourceforge.net/

Of course, not all of the improvements are my own work.  Many people
have been kind enough to contribute bug fixes and features.  This is
the version of php-mode which I maintain:

https://github.com/ejmr/php-mode

I simply wanted to share this updated mode in case any developers
using Emacs find it useful.

--
ejmr
南無妙法蓮華經

--- End Message ---

Reply via email to