473,473 Members | 1,419 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

eregi whitespace detection problem

I'm having trouble detecting whitespaces in strings.

Set up this test:

echo "<br>example 1:".intval(eregi("^\s","teststring"));
echo "<br>example 2:".intval(eregi("^\s","test string"));

Both resulting in 0 (zero)

also tried [:space:] and [:blank:] without result

Who can help this regular newbie expressing himself ?
Jul 17 '05 #1
2 4020
On Sat, 30 Oct 2004 15:53:11 +0200, "Frank" <fr***********@hotmail.com> wrote:
I'm having trouble detecting whitespaces in strings.

Set up this test:

echo "<br>example 1:".intval(eregi("^\s","teststring"));
echo "<br>example 2:".intval(eregi("^\s","test string"));

Both resulting in 0 (zero)
Which is correct. Your pattern is looking for:

^ - start of line
\s - followed by the literal string 's'

Consider:

echo "<br>example 3:".intval(eregi("^\s","string test"));

Output:

example 3:1

Because that does start with an 's'.
also tried [:space:] and [:blank:] without result

Who can help this regular newbie expressing himself ?


For starters don't use ereg, use the preg functions, they're better for
numerous reasons.

http://uk.php.net/manual/en/ref.pcre.php

It looks like you're already trying to use Perl-compatible expressions, since
you used \s. This would work if you used preg_match, as \s means whitespace in
Perl-compatible expressions, but not in POSIX expressions (as used by ereg).
You then just need to remove the leading ^.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2
Thanks Andy! You're a timesaver!

Frank

"Andy Hassall" <an**@andyh.co.uk> schreef in bericht
news:i7********************************@4ax.com...
On Sat, 30 Oct 2004 15:53:11 +0200, "Frank" <fr***********@hotmail.com>
wrote:
I'm having trouble detecting whitespaces in strings.

Set up this test:

echo "<br>example 1:".intval(eregi("^\s","teststring"));
echo "<br>example 2:".intval(eregi("^\s","test string"));

Both resulting in 0 (zero)


Which is correct. Your pattern is looking for:

^ - start of line
\s - followed by the literal string 's'

Consider:

echo "<br>example 3:".intval(eregi("^\s","string test"));

Output:

example 3:1

Because that does start with an 's'.
also tried [:space:] and [:blank:] without result

Who can help this regular newbie expressing himself ?


For starters don't use ereg, use the preg functions, they're better for
numerous reasons.

http://uk.php.net/manual/en/ref.pcre.php

It looks like you're already trying to use Perl-compatible expressions,
since
you used \s. This would work if you used preg_match, as \s means
whitespace in
Perl-compatible expressions, but not in POSIX expressions (as used by
ereg).
You then just need to remove the leading ^.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jane Doe | last post by:
Hi I took a quick look in the archives, but didn't find an answer to this one. I'd like to display a list of HTML files in a directory, showing the author's name between brackets after the...
5
by: george | last post by:
(driving me nuts) Hi there. I wonder if anyone can help? I'm including a page from Google in search.php, passing some parameters. So far so good. Then I'm asking to look through that Google...
25
by: Dynamo | last post by:
Hi The following script was taken from John Coggeshall's (PHP consultant) in his article on Zends site at http://www.zend.com/zend/spotlight/ev12apr.php // Get the email address to validate...
60
by: Fotios | last post by:
Hi guys, I have put together a flexible client-side user agent detector (written in js). I thought that some of you may find it useful. Code is here: http://fotios.cc/software/ua_detect.htm ...
1
by: news | last post by:
God, I have read every comment in php.net eregi and Google searched, and I have tried so many different attempts...this is the closest I've gotten to verify a variable contains only:...
9
by: Walter Roberson | last post by:
I have run into a peculiarity with SGI's C compiler (7.3.1.2m). I have been reading carefully over the ANSI X3.159-1989 specification, but I cannot seem to find a justification for the behaviour....
4
by: Nel | last post by:
Hi all, I am struggling with understanding a small eregi problem in php4. My code: <?PHP $htmlsource = '<img src="pics/hotdog.gif"> text text <img src="pics/silly%20sausage.gif"> ';...
1
by: fade2gray | last post by:
Hi, (new to group and a php novice) I'm editing some files using exapmles for reference. (1) // if (!eregi("admin.php", $_SERVER)) { die ("Access Denied"); } (2) if ( !defined('ADMIN_FILE')...
10
by: Conrad Lender | last post by:
In a recent thread in this group, I said that in some cases object detection and feature tests weren't sufficient in the development of cross-browser applications, and that there were situations...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.