Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Easy Regular Expressions Question

Posted on 2004-08-07
2
Medium Priority
?
265 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 32

Assisted Solution

by:ldbkutty
ldbkutty earned 100 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 200 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

722 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