Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #14491
| From | Matthew Carter <m@ahungry.com> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Purpose for a str_replace with an embedded print_r return |
| Date | 2014-11-06 00:09 -0500 |
| Organization | Ahungry (http://ahungry.com) |
| Message-ID | <87sihwyky9.fsf@ahungry.com> (permalink) |
| References | (2 earlier) <m3dgqc$vk3$1@dont-email.me> <8761etz7yv.fsf@ahungry.com> <m3e6lk$140$2@dont-email.me> <87wq79xap0.fsf@ahungry.com> <m3eta5$dhn$10@dont-email.me> |
Denis McMahon <denismfmcmahon@gmail.com> writes:
> On Wed, 05 Nov 2014 22:35:55 -0500, Matthew Carter wrote:
>
>> Jerry - this is not a case of browser encoding it differently - put the
>> snippet in a page and do a curl call via CLI to the page.
>
> You're still missing the point, in that you're looking at the visual
> representation which is controlled by the character set in use at the
> point of display (whether that's CLI, web page, inside a word document or
> whatever).
>
> We're looking at the internal machine representation of the output of the
> explode function, ie comparing:
>
> explode("\n", str_replace("\r\n", "\n", print_r($t, true)));
>
> with:
>
> explode("\n", str_replace("\r\n", "\n", $t));
>
> although you could probably step back a level and look at the input to
> the explode function, ie compare:
>
> str_replace("\r\n", "\n", print_r($t, true));
>
> with:
>
> str_replace("\r\n", "\n", $t);
>
> or even more fundamentally, compare:
>
> print_r($t, true) === $t
>
> but we're talking about a comparison of the two values made internally
> within the code using the '===' operator, not some arbitrary comparison
> made after the output has been processed by the graphics code of some
> display processor based on some arbitrary data relating to how certain
> numeric values should be presented graphically on a screen based on font
> choices etc.
>
> The only value of using the print_r version that I can see is that it
> will fail more gracefully than str_replace will if you hand it a non
> string parameter, but then the following code probably isn't going to get
> the sort of string it expects, so that may well bomb anyway.
>
> And this is a very lazy (and possibly stupid) way of handling such a
> case, it would be better to detect such a case ($t not being a string)
> earlier and fix it, and in well written code, $t would only not be a
> string if it wasn't defined, because you wouldn't reuse a non string
> variable as a string variable etc.
>
> Checking for $t not being defined would be better done with isdef().
I've never heard of isdef() - do you mean isset()?
--
Matthew Carter (m@ahungry.com)
http://ahungry.com
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Purpose for a str_replace with an embedded print_r return Dave Patoch <earthlydilemma@gmail.com> - 2014-11-04 06:20 -0800
Re: Purpose for a str_replace with an embedded print_r return "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-04 16:08 +0100
Re: Purpose for a str_replace with an embedded print_r return Dave Patoch <earthlydilemma@gmail.com> - 2014-11-04 07:27 -0800
Re: Purpose for a str_replace with an embedded print_r return Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-04 16:58 +0100
Re: Purpose for a str_replace with an embedded print_r return "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-04 18:58 +0100
Re: Purpose for a str_replace with an embedded print_r return Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-04 13:54 -0500
Re: Purpose for a str_replace with an embedded print_r return Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-05 14:27 +0100
Re: Purpose for a str_replace with an embedded print_r return Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-05 08:46 -0500
Re: Purpose for a str_replace with an embedded print_r return Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-05 15:32 +0100
Re: Purpose for a str_replace with an embedded print_r return Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-05 10:44 -0500
Re: Purpose for a str_replace with an embedded print_r return Matthew Carter <m@ahungry.com> - 2014-11-05 15:50 -0500
Re: Purpose for a str_replace with an embedded print_r return Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-05 16:59 -0500
Re: Purpose for a str_replace with an embedded print_r return "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-05 23:56 +0100
Re: Purpose for a str_replace with an embedded print_r return Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-06 04:30 +0100
Re: Purpose for a str_replace with an embedded print_r return Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-05 22:53 -0500
Re: Purpose for a str_replace with an embedded print_r return Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-05 15:07 +0000
Re: Purpose for a str_replace with an embedded print_r return Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-05 10:47 -0500
Re: Purpose for a str_replace with an embedded print_r return Matthew Carter <m@ahungry.com> - 2014-11-05 15:51 -0500
Re: Purpose for a str_replace with an embedded print_r return Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-05 17:00 -0500
Re: Purpose for a str_replace with an embedded print_r return Matthew Carter <m@ahungry.com> - 2014-11-05 22:35 -0500
Re: Purpose for a str_replace with an embedded print_r return Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-05 22:55 -0500
Re: Purpose for a str_replace with an embedded print_r return Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-06 04:26 +0000
Re: Purpose for a str_replace with an embedded print_r return Matthew Carter <m@ahungry.com> - 2014-11-06 00:09 -0500
Re: Purpose for a str_replace with an embedded print_r return Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-06 23:59 +0000
Re: Purpose for a str_replace with an embedded print_r return "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-06 18:43 +0100
Re: Purpose for a str_replace with an embedded print_r return Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-06 02:39 +0000
Re: Purpose for a str_replace with an embedded print_r return Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-06 02:44 +0000
Re: Purpose for a str_replace with an embedded print_r return Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-05 22:56 -0500
csiph-web