Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-22-2010, 12:01 PM   PM User | #1
john_zakaria
Regular Coder

 
Join Date: Dec 2008
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
john_zakaria can only hope to improve
ensure that word exists in variable

Hello everybody..

i select website addresses from database all that i need is ensure that is '.com' exists in variable or not

for example:
if $x[1]='www.yahoo.com' --> return true.

but if $x[1]='www.yahoo' --> return false with error message website is not entered correctly.

thanks in advance
john_zakaria is offline   Reply With Quote
Old 03-22-2010, 12:28 PM   PM User | #2
JAY6390
Regular Coder

 
Join Date: Dec 2009
Location: UK
Posts: 495
Thanks: 0
Thanked 58 Times in 58 Posts
JAY6390 is on a distinguished road
Use:
http://www.php.net/strstr

Search for .com in the string and it will return false if it isn't in the string
PHP Code:
if(strstr($x[1], '.com') !== false) {
    
// Action if .com exists here
}else{
    
// Action if .com doesn't exist here

__________________
My site: JayGilford.com
Resources:
PHP Pagination Class | Getting all page links | Handling PHP Errors properly
If you like a users help, show your appreciation with the rep and thanks buttons :)
JAY6390 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:11 AM.


Advertisement
Log in to turn off these ads.