Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Does this exist? Compare variables.
Old 04-29-2010, 04:54 PM Does this exist? Compare variables.
grafitti's Avatar
Novice Talker

Posts: 9
Trades: 0
I want to compare variables strings just like you do in mysql except in a if statement. I know this wont work but a perfect example would be.

PHP Code:
if($var == %info%) { echo 'this works'; }
//if the variable contains the words info in it echo this works. 
grafitti is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-29-2010, 05:20 PM Re: Does this exist? Compare variables.
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
http://php.net/manual/en/function.strrpos.php

http://php.net/manual/en/function.preg-match.php
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-29-2010, 06:30 PM Re: Does this exist? Compare variables.
grafitti's Avatar
Novice Talker

Posts: 9
Trades: 0
Thanks I'm going to also look up regular expression, hopefully it helps.
grafitti is offline
Reply With Quote
View Public Profile
 
Old 04-30-2010, 11:11 AM Re: Does this exist? Compare variables.
Extreme Talker

Posts: 181
Name: David Jackson
Trades: 0
http://php.net/manual/en/function.strcmp.php
__________________

Please login or register to view this content. Registration is FREE
davidj is offline
Reply With Quote
View Public Profile
 
Old 04-30-2010, 11:27 AM Re: Does this exist? Compare variables.
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
using strpos will tell you the position of the word your looking for.

If it returns a position, You know it exists ( you dont care about the position )
But the fact that its found one, tells you that its found the word.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 05-01-2010, 03:24 AM Re: Does this exist? Compare variables.
Marik's Avatar
Skilled Talker

Posts: 99
Trades: 0
Using strpos:

PHP Code:
<?php

$hayStack 
"The needle lies in the haystack";

if (
strpos($hayStack"needle")) {
    echo 
"Word exists in that string!";
} else {
    echo 
"Word doesn't exist in that string.";
}
    
?>

Last edited by Marik; 05-01-2010 at 03:41 AM..
Marik is offline
Reply With Quote
View Public Profile
 
Old 05-01-2010, 04:10 AM Re: Does this exist? Compare variables.
Banned

Posts: 2
Trades: 0
Daily I am looking the expression now a day.

__________________
Ashley06 is offline
Reply With Quote
View Public Profile
 
Old 05-01-2010, 04:37 AM Re: Does this exist? Compare variables.
Extreme Talker

Posts: 181
Name: David Jackson
Trades: 0
Why not use the strcmp (STRING COMPARE) function??

http://php.net/manual/en/function.strcmp.php

Perfect for comparing strings
__________________

Please login or register to view this content. Registration is FREE
davidj is offline
Reply With Quote
View Public Profile
 
Old 05-01-2010, 06:23 AM Re: Does this exist? Compare variables.
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by davidj View Post
Why not use the strcmp (STRING COMPARE) function??

http://php.net/manual/en/function.strcmp.php

Perfect for comparing strings
I believe the OP is trying to determine if an input string contains a substring. strcmp compares strings lexicographically.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Reply     « Reply to Does this exist? Compare variables.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.86547 seconds with 12 queries