If you just want to test for \n\r -
if ( substr ( -2, $my_string ) == "\n\r" ) { // substr with the
negative value of 2 will give you the last two characters of your string
// do some stuff
}
I think it would be a good idea to explain a little bit more what you
are trying to accomplish. Are you preparing the string for a database
insert? Do you want to sanitise the string?
Stripping off those kind of characters can also be done with trim (or
ltrim - trims white space characters from the left of the string or
rtim - trims from the right). Read the manual for more details and
options.
If you are not quite sure what those characters are, you can find out
with this little helper.
$characters = preg_split( '//', $my_string );
foreach ( $characters as $character ) {
echo "ASCI value of the character {$character} is: " . ord
( $character ) . "<br />\n";
}
Then you can look up the values in a ASCI table.
/frank
29 dec 2006 kl. 11.01 skrev Peter Lauri:
Try:
$string_as_array = explode("\n", $string);
echo "<pre>";
print_r($string_as_array);
echo "</pre>";
The array that you get will contain segments of the string that is
separated
with \n. Let me know if that helps.
Best regards,
Peter Lauri
www.dwsasia.com - company web site
www.lauri.se - personal web site
www.carbonfree.org.uk - become Carbon Free
-----Original Message-----
From: Angelo Zanetti [mailto:[EMAIL PROTECTED]
Sent: Friday, December 29, 2006 10:43 AM
To: PHP List
Subject: [PHP] help with \n\r in strings
Hi all,
I receive a text file with a whole bunch of strings. and each line is
terminated by what I presume is \n\r however when I read the string
into
PHP, it seems that the last column of the row and the first column of
the next row are connected but it appears as a space but I've done all
kinds of tests like $spacePos = strrpos($dateAmount, ' '); but this is
always empty.
So is there a way to test for \r\n? or what else can I use to delimit
these two values (last column of row and first column of next row)?
Thanks in advance.
Angelo
--
----------------------------------------------------------------------
--
Angelo Zanetti
Systems developer
----------------------------------------------------------------------
--
*Telephone:* +27 (021) 469 1052
*Mobile:* +27 (0) 72 441 3355
*Fax:* +27 (0) 86 681 5885
*
Web:* http://www.zlogic.co.za
*E-Mail:* [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php