Regex Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreRegex Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 23rd, 2009, 06:34 AM
luz luz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Posts: 6 luz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 31 m 59 sec
Reputation Power: 0
Php code problem with + symbol

hi all..i need some help with php code

i've have this code
Code:
$ValResult=0;
preg_match_all('/^[a-zA-Z- .,]{2,200}$/', $Valstring, $matches);
	foreach($matches[0] as $value){
		if($value!='' || $value!='0' || $value!='null'){
			$ValResult=1;
		 }	
		 else{
			$ValResult=0;
		 }			
	}
	 return $ValResult; 


and try it with

1)$Valstring='hulu'; and its return $ValResult=1--ok
2)$Valstring='hulu-'; and its return $ValResult=1--ok
3)$Valstring='hulu123'; and its return $ValResult=0--ok
4)$Valstring='hulu]'; and its return $ValResult=0--ok

but the when i try it with

5)$Valstring='hulu+'; and its return $ValResult=1--not ok

it suppose to return $ValResult=0

can someone help me with..thanking you all in advance for reviewing my post

Reply With Quote
  #2  
Old January 23rd, 2009, 09:29 AM
ManiacDan's Avatar
ManiacDan ManiacDan is offline
Sarcky
Dev Shed God 10th Plane (9500 - 9999 posts)
 
Join Date: Oct 2006
Location: Pennsylvania, USA
Posts: 9,917 ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)  Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 2 Months 3 Weeks 1 Day 10 h 25 m 30 sec
Reputation Power: 6113
I ran your code and got the correct results:
PHP Code:
<?php
function check_string($Valstring) {
    
$ValResult=0;
preg_match_all('/^[a-zA-Z- .,]{2,200}$/'$Valstring$matches);
    foreach(
$matches[0] as $value){
        if(
$value!='' || $value!='0' || $value!='null'){
            
$ValResult=1;
         }  
         else{
            
$ValResult=0;
         }          
    }
     return 
$ValResult
}

$array = array("hulu""hulu-""hulu123""hulu]""hulu+");
foreach ( 
$array AS $Valstring ) {
    echo 
"$Valstring has a result of " check_string($Valstring) . "\n";
}
?>
However, this is a very inefficient way of doing this. A better function:
PHP Code:
<?php
function check_string($Valstring) {
    if ( 
preg_match('/^[a-zA-Z .,-]{2,200}$/'$Valstring) ) {
        return 
1;
    }
    return 
0
}

$array = array("hulu""hulu-""hulu123""hulu]""hulu+");
foreach ( 
$array AS $Valstring ) {
    echo 
"$Valstring has a result of " check_string($Valstring) . "\n";
}
?>
Both of these output:
Code:
hulu has a result of 1
hulu- has a result of 1
hulu123 has a result of 0
hulu] has a result of 0
hulu+ has a result of 0
-Dan
__________________
HEY! YOU! Read the New User Guide and Forum Rules

"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > Php code problem with + symbol

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap