Solved

How Can I test (true or false) on this regex statement: $pattern = '/\/ /';

Posted on 2009-04-02
4
396 Views
Last Modified: 2012-05-06
How Can I test (true or false) on this regex statement:
$pattern = '/\/ /';

So, I want to return TRUE if there's more than two slashes in a row.
0
Comment
Question by:level9wizard
[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
4 Comments
 
LVL 13

Accepted Solution

by:
marchent earned 350 total points
ID: 24053533

$str = "Hello // world ////, how are/// you?";
 
## if string has 2 or more / on it
if( preg_match('|/{2,}|', $str) ){
    return true;
}

Open in new window

0
 
LVL 10

Assisted Solution

by:aboo_s
aboo_s earned 50 total points
ID: 24053571
I'm not sure I got it, but anyway here you go:

$k=0;

for($i=0;$i<strlen($pattern);$i++)
   
      if($pattern[$i]=='\')
                               
                               $k++;
   if($k>1)

            echo 'true';

                              else echo 'false' ;
0
 
LVL 5

Assisted Solution

by:prokvk
prokvk earned 50 total points
ID: 24053761
Here you go:



<?php
    
        $s = 'asdad // dasfsd / dsdfsdfs';
        
        if (ereg('([/]{3,})',$s))
        {
            echo 'ok';
        }
        else
        {
            echo 'NOT ok';
        }
    
    ?>

Open in new window

0
 
LVL 15

Assisted Solution

by:fsze88
fsze88 earned 50 total points
ID: 24056344
<?
$str = 'Hello // world ////, how are/// you?';

$pattern = '/\/+/';
$replacement = '/';

   
       
        if (ereg('\/{2,}',$str))
        {
            echo 'yes, more than one / there';
        }
        else
        {
            echo 'no double /';
        }
   
echo preg_replace($pattern, $replacement, $str);
//echo str_replace($pattern, $replacement, $str);

?>
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

730 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