Solved

Easy Regular Expressions Question

Posted on 2004-08-07
2
257 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
Comment Utility
<?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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
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…
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 look for a specific file type in a local or remote server directory using PHP.

762 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

13 Experts available now in Live!

Get 1:1 Help Now