Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #11981 > unrolled thread
| Started by | bill <william@TechServSys.com> |
|---|---|
| First post | 2013-11-25 11:12 -0500 |
| Last post | 2013-11-28 11:09 -0500 |
| Articles | 19 — 7 participants |
Back to article view | Back to comp.lang.php
finding newlines bill <william@TechServSys.com> - 2013-11-25 11:12 -0500
Re: finding newlines Christoph Michael Becker <cmbecker69@arcor.de> - 2013-11-25 17:32 +0100
Re: finding newlines bill <william@TechServSys.com> - 2013-11-26 09:36 -0500
Re: finding newlines Richard Yates <richard@yatesguitar.com> - 2013-11-25 08:34 -0800
Re: finding newlines Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-25 20:11 +0000
Re: finding newlines Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-25 22:23 +0100
Re: finding newlines Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-26 18:05 +0000
Re: finding newlines Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-26 19:46 +0100
Re: finding newlines Wizard-Of-Oz <somewhere@over.rainbow.com> - 2013-11-30 16:50 +0000
Re: finding newlines Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-12-01 17:11 +0100
Re: finding newlines Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-25 22:18 +0100
Re: finding newlines Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-25 16:36 -0500
Re: finding newlines bill <william@TechServSys.com> - 2013-11-27 05:11 -0500
Re: finding newlines Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-27 16:56 +0100
Re: finding newlines bill <william@TechServSys.com> - 2013-11-28 11:42 -0500
Re: finding newlines Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-28 20:20 +0100
Re: finding newlines Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-29 00:57 +0000
Re: finding newlines Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-27 11:47 -0500
Re: finding newlines bill <william@TechServSys.com> - 2013-11-28 11:09 -0500
| From | bill <william@TechServSys.com> |
|---|---|
| Date | 2013-11-25 11:12 -0500 |
| Subject | finding newlines |
| Message-ID | <l6vst0$ijk$1@speranza.aioe.org> |
I am trying to find the first line bread in a string where string = "Hand Carried by Patient\n\nTo Whom It May Concern:\n\nR...." This code does not work: $pos = strpos($progressNote,"\n\n"); it returns pos = false where do I err? bill
[toc] | [next] | [standalone]
| From | Christoph Michael Becker <cmbecker69@arcor.de> |
|---|---|
| Date | 2013-11-25 17:32 +0100 |
| Message-ID | <52937bb1$0$6554$9b4e6d93@newsspool4.arcor-online.net> |
| In reply to | #11981 |
bill wrote: > I am trying to find the first line bread in a string > where string = "Hand Carried by Patient\n\nTo Whom It May > Concern:\n\nR...." > > This code does not work: $pos = strpos($progressNote,"\n\n"); > it returns pos = false > > where do I err? Um, the code should work, if $progressNote does contain a *double* newline character. Have you confirmed that $progressNote indeed contains what you expect? You may try looking for a *single* newline character: $pos = strpos($progressNote, "\n"); -- Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | bill <william@TechServSys.com> |
|---|---|
| Date | 2013-11-26 09:36 -0500 |
| Message-ID | <l72bla$8mi$1@speranza.aioe.org> |
| In reply to | #11982 |
On 11/25/2013 11:32 AM, Christoph Michael Becker wrote: > bill wrote: > >> I am trying to find the first line bread in a string >> where string = "Hand Carried by Patient\n\nTo Whom It May >> Concern:\n\nR...." >> >> This code does not work: $pos = strpos($progressNote,"\n\n"); >> it returns pos = false >> >> where do I err? > > Um, the code should work, if $progressNote does contain a *double* > newline character. Have you confirmed that $progressNote indeed > contains what you expect? You may try looking for a *single* newline > character: > > $pos = strpos($progressNote, "\n"); > the text above is the exact text I am searching. The statement is: $pos = stripos($progressNote,"\n\n"); echo basename(__FILE__) . ": " . __LINE__ . ":pos= $pos, first string = >" . substr($progressNote, 0, $pos). "<<br />";
[toc] | [prev] | [next] | [standalone]
| From | Richard Yates <richard@yatesguitar.com> |
|---|---|
| Date | 2013-11-25 08:34 -0800 |
| Message-ID | <btu699pvra7vtft86tsoknggi1veqrbobv@4ax.com> |
| In reply to | #11981 |
On Mon, 25 Nov 2013 11:12:17 -0500, bill <william@TechServSys.com> wrote: >I am trying to find the first line bread in a string >where string = "Hand Carried by Patient\n\nTo Whom It May >Concern:\n\nR...." > >This code does not work: $pos = strpos($progressNote,"\n\n"); >it returns pos = false > >where do I err? > >bill Best to include your actual code so typos can be spotted. This works, but I do not know how it differs from yours: <?php $progressNote="Hand Carried by Patient\n\nTo Whom It May Concern:\n\n"; $pos = strpos($progressNote,"\n\n"); echo $pos; exit; // result is 23 which is correct ?>
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2013-11-25 20:11 +0000 |
| Message-ID | <l70ats$mhk$1@dont-email.me> |
| In reply to | #11981 |
On Mon, 25 Nov 2013 11:12:17 -0500, bill wrote:
> I am trying to find the first line bread in a string where string =
> "Hand Carried by Patient\n\nTo Whom It May Concern:\n\nR...."
>
> This code does not work: $pos = strpos($progressNote,"\n\n");
> it returns pos = false
>
> where do I err?
If you're trying to find lines in a multiline string, you could try
splitting the string on newline characters:
$lines=explode("\n",$progressNote);
Then you can work through $lines looking for relevant ones.
Note that you may have some empty strings in $lines, and also that you
may have \r\n where you expect \n.
A better mechanism may be:
$lines=explode("\n",preg_replace("/[\r\n]+/","\n",$progressNote));
Which will change all instances of any combination of one or more
newlines and / or carriage returns to a single newline, and then split
the string on the newline character.
--
Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2013-11-25 22:23 +0100 |
| Message-ID | <2318878.Cf5I4tO75m@PointedEars.de> |
| In reply to | #11984 |
Denis McMahon wrote:
> A better mechanism may be:
>
> $lines=explode("\n",preg_replace("/[\r\n]+/","\n",$progressNote));
>
> Which will change all instances of any combination of one or more
> newlines and / or carriage returns to a single newline, and then split
> the string on the newline character.
$lines = preg_split('/[\\r\\n]+/', $progressNote);
or (having empty lines as empty-string array elements)
$lines = preg_split('/\\r?\\n|\\r/', $progressNote);
See also: <http://php.net/file>
PointedEars
--
When all you know is jQuery, every problem looks $(olvable).
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2013-11-26 18:05 +0000 |
| Message-ID | <l72nu1$ghd$1@dont-email.me> |
| In reply to | #11984 |
On Mon, 25 Nov 2013 20:11:40 +0000, Denis McMahon wrote:
> $lines=explode("\n",preg_replace("/[\r\n]+/","\n",$progressNote));
or of course:
$lines=preg_split("/[\r\n]+/",$progressNote);
--
Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2013-11-26 19:46 +0100 |
| Message-ID | <3047167.u27dj7xdmW@PointedEars.de> |
| In reply to | #11992 |
Denis McMahon wrote:
> On Mon, 25 Nov 2013 20:11:40 +0000, Denis McMahon wrote:
>> $lines=explode("\n",preg_replace("/[\r\n]+/","\n",$progressNote));
>
> or of course:
>
> $lines=preg_split("/[\r\n]+/",$progressNote);
Now that I told you. However, “of course” *that* is questionable: within
double-quotes, “\r” and “\n” are expanded as *string* escape sequences,
before preg_split() sees them. When in doubt, use either single-quotes or
double-quotes with double-backslash.
I prefer to use double-backslash also with single-quotes in case someone
decides in the future to support more escape sequences. The resulting code
style also is more consistent because with trailing backslash you *must* use
double-backslash unless you want to escape the string delimiter: '\' is
likely to become a syntax error (unterminated string literal); '\\' is not.
PointedEars
--
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
-- Richard Cornford, cljs, <cife6q$253$1$8300dec7@news.demon.co.uk> (2004)
[toc] | [prev] | [next] | [standalone]
| From | Wizard-Of-Oz <somewhere@over.rainbow.com> |
|---|---|
| Date | 2013-11-30 16:50 +0000 |
| Message-ID | <l7d509$ct7$5@speranza.aioe.org> |
| In reply to | #11993 |
Thomas 'PointedEars' Lahn wrote: > Now that I told you. However, “of course” *that* is questionable: > within double-quotes, “\r” and “\n” are expanded as *string* escape > sequences, > before preg_split() sees them. When in doubt, use either single-quotes > or double-quotes with double-backslash. Are you sure?
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2013-12-01 17:11 +0100 |
| Message-ID | <2197574.q5M6EdDCNi@PointedEars.de> |
| In reply to | #12044 |
Wizard-Of-Oz wrote: ^^^^^^^^^^^^ > Thomas 'PointedEars' Lahn wrote: >> Now that I told you. However, “of course” *that* is questionable: >> within double-quotes, “\r” and “\n” are expanded as *string* escape >> sequences, before preg_split() sees them. When in doubt, use either >> single-quotes or double-quotes with double-backslash. > > Are you sure? Who's asking? PointedEars -- Prototype.js was written by people who don't know javascript for people who don't know javascript. People who don't know javascript are not the best source of advice on designing systems that use javascript. -- Richard Cornford, cljs, <f806at$ail$1$8300dec7@news.demon.co.uk>
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2013-11-25 22:18 +0100 |
| Message-ID | <1626298.k0UxW9GDbk@PointedEars.de> |
| In reply to | #11981 |
bill wrote:
> I am trying to find the first line bread in a string
> where string = "Hand Carried by Patient\n\nTo Whom It May
^^^^^^^^^^^^^^
For some reason I read “tomato” there at first ;-)
> Concern:\n\nR...."
>
> This code does not work: $pos = strpos($progressNote,"\n\n");
> it returns pos = false
No, it does not:
$ php -r 'var_dump(strpos("Hand Carried by Patient\n\nTo Whom It May",
"\n\n"));'
int(23)
> where do I err?
$progressNote !== "Hand Carried by Patient\n\n…"
PHP’s string functions are tricky; when in doubt, RTFM.
PointedEars
--
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
-- Richard Cornford, cljs, <cife6q$253$1$8300dec7@news.demon.co.uk> (2004)
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2013-11-25 16:36 -0500 |
| Message-ID | <l70fsg$7dg$1@dont-email.me> |
| In reply to | #11981 |
On 11/25/2013 11:12 AM, bill wrote: > I am trying to find the first line bread in a string > where string = "Hand Carried by Patient\n\nTo Whom It May > Concern:\n\nR...." > > This code does not work: $pos = strpos($progressNote,"\n\n"); > it returns pos = false > > where do I err? > > bill How did you get the string in $progressNote? Did you set it yourself, or was it possibly sourced from a web page? What do you get if you echo $progressNote? -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | bill <william@TechServSys.com> |
|---|---|
| Date | 2013-11-27 05:11 -0500 |
| Message-ID | <l74gg6$tr7$1@speranza.aioe.org> |
| In reply to | #11987 |
On 11/25/2013 4:36 PM, Jerry Stuckle wrote: > On 11/25/2013 11:12 AM, bill wrote: >> I am trying to find the first line bread in a string >> where string = "Hand Carried by Patient\n\nTo Whom It May >> Concern:\n\nR...." >> >> This code does not work: $pos = strpos($progressNote,"\n\n"); >> it returns pos = false >> >> where do I err? >> >> bill > > How did you get the string in $progressNote? Did you set it > yourself, or was it possibly sourced from a web page? > > What do you get if you echo $progressNote? > > I create the progress note in another script that is POSTed to this one. looking at progress note tells me that is is as I said, actually, I copied it from the display of the debug statement: echo basename(__FILE__) . ": " . __LINE__ . ":progNote=>$progressNote<<br />"; As it should work, and does not, I will spend more time on it tomorrow (when I have the time. thanks bill
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2013-11-27 16:56 +0100 |
| Message-ID | <1731929.8bB35ViQIY@PointedEars.de> |
| In reply to | #11995 |
bill wrote:
> I create the progress note in another script that is POSTed to
> this one.
>
> looking at progress note tells me that is is as I said, actually,
> I copied it from the display of the debug statement:
>
> echo basename(__FILE__) . ": " . __LINE__ .
> ":progNote=>$progressNote<<br />";
^
This is almost certainly an error. Also, you want to htmlspecialchars()
etc. the value of $progressNote.
PointedEars
--
When all you know is jQuery, every problem looks $(olvable).
[toc] | [prev] | [next] | [standalone]
| From | bill <william@TechServSys.com> |
|---|---|
| Date | 2013-11-28 11:42 -0500 |
| Message-ID | <l77rq5$pbb$1@speranza.aioe.org> |
| In reply to | #11999 |
On 11/27/2013 10:56 AM, Thomas 'PointedEars' Lahn wrote: > bill wrote: > >> I create the progress note in another script that is POSTed to >> this one. >> >> looking at progress note tells me that is is as I said, actually, >> I copied it from the display of the debug statement: >> >> echo basename(__FILE__) . ": " . __LINE__ . >> ":progNote=>$progressNote<<br />"; > ^ > This is almost certainly an error. Also, you want to htmlspecialchars() > etc. the value of $progressNote. > > > PointedEars > actually, not an error. I use the open and close bracket characters to help me see the string and not miss spaces on either end. bill
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2013-11-28 20:20 +0100 |
| Message-ID | <2269997.ZKPhRHLOFA@PointedEars.de> |
| In reply to | #12007 |
bill wrote: > On 11/27/2013 10:56 AM, Thomas 'PointedEars' Lahn wrote: >> bill wrote: >>> I create the progress note in another script that is POSTed to >>> this one. >>> >>> looking at progress note tells me that is is as I said, actually, >>> I copied it from the display of the debug statement: >>> >>> echo basename(__FILE__) . ": " . __LINE__ . >>> ":progNote=>$progressNote<<br />"; >> ^ >> This is almost certainly an error. Also, you want to htmlspecialchars() >> etc. the value of $progressNote. > > actually, not an error. I use the open and close bracket > characters to help me see the string and not miss spaces on > either end. “<br />” is either XHTML or HTML5 syntax. In HTML, in XHTML and in other XML applications, “<” and ”>” are special markup characters (Start-Tag Open [STAGO] and Tag Close [TAGC]). You need to escape literal ”<” (in order to prevent it from being parsed as STAGO, at least when a letter follows) and you should escape literal ”>” (if only to avoid confusion). PHP's htmlspecialchars() also does that for you. <http://validator.w3.org/> PointedEars -- Prototype.js was written by people who don't know javascript for people who don't know javascript. People who don't know javascript are not the best source of advice on designing systems that use javascript. -- Richard Cornford, cljs, <f806at$ail$1$8300dec7@news.demon.co.uk>
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2013-11-29 00:57 +0000 |
| Message-ID | <l78op1$d3a$1@dont-email.me> |
| In reply to | #12007 |
On Thu, 28 Nov 2013 11:42:50 -0500, bill wrote: > On 11/27/2013 10:56 AM, Thomas 'PointedEars' Lahn wrote: >> bill wrote: >> >>> I create the progress note in another script that is POSTed to this >>> one. >>> >>> looking at progress note tells me that is is as I said, actually, >>> I copied it from the display of the debug statement: >>> >>> echo basename(__FILE__) . ": " . __LINE__ . >>> ":progNote=>$progressNote<<br />"; >> ^ >> This is almost certainly an error. Also, you want to >> htmlspecialchars() >> etc. the value of $progressNote. > actually, not an error. I use the open and close bracket characters to > help me see the string and not miss spaces on either end. If you're outputting this in an xhtml document, that's an incredibly bad idea. You should use > and < instead. echo basename(__FILE__) . ": " . __LINE__ . ":progNote=>$progressNote<<br />"; -- Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2013-11-27 11:47 -0500 |
| Message-ID | <l757ne$ncm$1@dont-email.me> |
| In reply to | #11995 |
On 11/27/2013 5:11 AM, bill wrote: > On 11/25/2013 4:36 PM, Jerry Stuckle wrote: >> On 11/25/2013 11:12 AM, bill wrote: >>> I am trying to find the first line bread in a string >>> where string = "Hand Carried by Patient\n\nTo Whom It May >>> Concern:\n\nR...." >>> >>> This code does not work: $pos = strpos($progressNote,"\n\n"); >>> it returns pos = false >>> >>> where do I err? >>> >>> bill >> >> How did you get the string in $progressNote? Did you set it >> yourself, or was it possibly sourced from a web page? >> >> What do you get if you echo $progressNote? >> >> > I create the progress note in another script that is POSTed to this one. > > looking at progress note tells me that is is as I said, actually, I > copied it from the display of the debug statement: > > echo basename(__FILE__) . ": " . __LINE__ . > ":progNote=>$progressNote<<br />"; > > As it should work, and does not, I will spend more time on it tomorrow > (when I have the time. > > thanks > > bill OK, in that case you have the characters '\' and 'n'. In PHP, "\n" is a newline character. You need to either escape the '\' as in "\\n\\n", or use single quotes around your string, i.e. '\n\n'. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | bill <william@TechServSys.com> |
|---|---|
| Date | 2013-11-28 11:09 -0500 |
| Message-ID | <l77pqr$k45$1@speranza.aioe.org> |
| In reply to | #12000 |
On 11/27/2013 11:47 AM, Jerry Stuckle wrote: > On 11/27/2013 5:11 AM, bill wrote: >> On 11/25/2013 4:36 PM, Jerry Stuckle wrote: >>> On 11/25/2013 11:12 AM, bill wrote: >>>> I am trying to find the first line bread in a string >>>> where string = "Hand Carried by Patient\n\nTo Whom It May >>>> Concern:\n\nR...." >>>> >>>> This code does not work: $pos = strpos($progressNote,"\n\n"); >>>> it returns pos = false >>>> >>>> where do I err? >>>> >>>> bill >>> >>> How did you get the string in $progressNote? Did you set it >>> yourself, or was it possibly sourced from a web page? >>> >>> What do you get if you echo $progressNote? >>> >>> >> I create the progress note in another script that is POSTed to >> this one. >> >> looking at progress note tells me that is is as I said, >> actually, I >> copied it from the display of the debug statement: >> >> echo basename(__FILE__) . ": " . __LINE__ . >> ":progNote=>$progressNote<<br />"; >> >> As it should work, and does not, I will spend more time on it >> tomorrow >> (when I have the time. >> >> thanks >> >> bill > > OK, in that case you have the characters '\' and 'n'. In PHP, > "\n" is a newline character. You need to either escape the '\' > as in "\\n\\n", or use single quotes around your string, i.e. > '\n\n'. > Very good - that was it. Thanks, bill
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web