Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #14462
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Purpose for a str_replace with an embedded print_r return |
| Date | 2014-11-04 16:58 +0100 |
| Organization | PointedEars Software (PES) |
| Message-ID | <2023723.LoZblivUAB@PointedEars.de> (permalink) |
| References | <bad4f2c1-102e-4115-94ea-c8f8efdaca0b@googlegroups.com> <m3aq5j$hii$1@solani.org> <064143e2-28d1-40e4-a76e-c6d28b05dddb@googlegroups.com> |
Dave Patoch wrote:
[restored context]
> Christoph M. Becker wrote:
>> Dave Patoch wrote:
>>> foreach(
>>> explode("\n", str_replace("\r\n", "\n", print_r($message, true))) as
>>> $msg)
>>>
>>> and
>>>
>>> foreach(
>>> explode("\n", str_replace("\r\n", "\n", $message)) as $msg)
>>
>> What type of value does $message hold?
>
> It's just a plain old string, which is why it confused me.
I think the proper idiom is “to kill two birds with one stone”. This
appears to be debug code, and if you pass “true” as second parameter to
print_r(), it returns the output instead of printing it.
<http://php.net/print_r>
The major advantage of print_r() over echo and print(), which always output
the *string representation* of a value, is that the type of the first
parameter does not matter for inspection: if it is a string or a number, the
result is a string or number; if it is an array, it contains the array keys
and values; and if it is a reference to an object, it contains the object's
class name and properties. var_dump()'s output is more detailed than
print_r()'s on the one hand, and trimmed at a point on the other, and
highlighting can be applied to that with Xdebug; but it cannot return the
output instead (you would have to output_buffer it yourself).
<http://php.net/echo>
<http://php.net/print>
<http://php.net/manual/en/language.oop5.magic.php#object.tostring>
<http://php.net/var_dump>
<http://xdebug.org/>
str_replace() then normalizes the value so that it can be explode()d, for
“foreach” iteration, without using regular expressions. This does not
account for Mac OS < 10.x newlines ("\r"), but there does not appear to be a
PHP release for those versions (anymore).
<http://php.net/str_replace>
<http://php.net/manual/en/install.php>
You are _not_ posting to a Web forum or bulletin board here, but to a Usenet
newsgroup where postings are read differently than in the Google Groups Web
archive, and where they usually expire. Therefore, please provide
attribution of quoted material, and a minimum of the context.
<http://www.netmeister.org/news/learn2quote.html>
--
PointedEars
Zend Certified PHP Engineer
Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.
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