Solved

Easy Regular Expressions Question

Posted on 2004-08-07
2
258 Views
Last Modified: 2012-05-05
Hi everyone - This shouldn't be too bad at all, but I know it would take me a while to figure it out so I'd appreciate the help.  I've got a variable containing 1 a string that looks something like this:

032|Robin|Scace|0|No Schedule|

All I want to do is test this string and make sure there are exactly 5 pipes in it, no more no less.

Thanks in advance!
0
Comment
Question by:blacksix
2 Comments
 
LVL 32

Assisted Solution

by:ldbkutty
ldbkutty earned 25 total points
ID: 11743004
<?php
$myString = "032|Robin|Scace|0|No Schedule|";
echo substr_count($myString, "|"); // prints out 5
?>
0
 
LVL 36

Accepted Solution

by:
Zyloch earned 50 total points
ID: 11743021
Hi

You mean something like

if (preg_match_all("/|{5}",$yourString)) {
   echo("There are exactly 5 pipes in the string.");
}

Regards,
Zyloch
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now