Solved

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

Posted on 2009-04-02
4
392 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
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
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.

747 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

8 Experts available now in Live!

Get 1:1 Help Now