Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP: Change a positive condition to negative.

Posted on 2009-04-07
2
Medium Priority
?
416 Views
Last Modified: 2012-05-06
How can I reverse this condition in my function so that I don't need an else?
<?php
 
chdir_safe('../something\file.txt');
 
function chdir_safe($dir)
{	
	
	if (substr($dir,0,1) == "/" || substr($dir,0,1) == "\\" || substr($dir,1,1) == ":" ){
		//url is absolute
	}
	else
	{
		echo "fix the url<br>";
	}
	
	echo $dir;
	exit;
}
?>

Open in new window

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
2 Comments
 
LVL 17

Expert Comment

by:Chris Harte
ID: 24087579
Use the logical 'not' prefix which is an exclamation mark "!"
<?php
 
chdir_safe('../something\file.txt');
 
function chdir_safe($dir)
{       
        
        if (!substr($dir, 0, 1) == "/" 
            || !substr($dir, 0, 1) == "\\" 
            || !substr($dir, 1, 1) == ":" )
        {
            echo "fix the url<br>";
        }
        
        echo $dir;
        exit;
}
?>

Open in new window

0
 
LVL 14

Accepted Solution

by:
shobinsun earned 2000 total points
ID: 24088136

Hello,

Use this:


<?php
 
chdir_safe('../something\file.txt');
 
function chdir_safe($dir)
{      
       
        if (!(substr($dir,0,1) == "/" || substr($dir,0,1) == "\\" || substr($dir,1,1) == ":" )){
                     
                echo "fix the url<br>";
        }
       
        echo $dir;
        exit;
}
?>
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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 receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

596 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