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
If X contains Y then ...
Old 04-18-2005, 01:15 PM If X contains Y then ...
Average Talker

Posts: 29
Trades: 0
what would i replace CONTAINS with in this code to have the condition if $this variable contains "this" then do this.

If ($this CONTAINS "this")
{do this} else
{do this}
__________________
-ValC
ValC is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-18-2005, 01:26 PM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
PHP Code:
if ($x == $y) {

/* Or if you want to have something like it equals 
    "happy days" then: if ($x == 'happy days') */
 
} else {


It really is much more worth your while to check the PHP Manual. It contains everything you need to know, and it's fast.
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill

Please visit my sites:
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by Republikin; 04-18-2005 at 05:46 PM.. Reason: You don't need to insult him, even playing.
leavethisplace is offline
Reply With Quote
View Public Profile
 
Old 04-18-2005, 01:28 PM
merlin's Avatar
Skilled Talker

Posts: 52
Trades: 0
If I understand the question,

Try is equal to.

PHP Code:
if ($setting1 == $setting2) {

Then do this

} else {

do 
this


Last edited by merlin; 04-18-2005 at 01:55 PM..
merlin is offline
Reply With Quote
View Public Profile
 
Old 04-18-2005, 02:14 PM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
PHP Code:
if (stripos($this,"this") === false) {
     
// do this for not found
} else {
    
// do this for found 

case insensitive and using === just in case "this" is at the start of the string
__________________
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 offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-18-2005, 02:17 PM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
complicating it a little
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill

Please visit my sites:
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
leavethisplace is offline
Reply With Quote
View Public Profile
 
Old 04-18-2005, 02:30 PM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
not really,

the question seemed to be if "this" is in string $this do something

I maybe wrong of course
it won't the first time today
__________________
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 offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-18-2005, 04:54 PM
Average Talker

Posts: 29
Trades: 0
yea u got it right chris

but the script u gave me returns this error

Fatal error: Call to undefined function: stripos() in /usr/local/psa/home/vhosts/enmotion.net/httpdocs/yearbook/mainbot.php on line 162

and thanks everyone for teaching me how to do a basic if function?!!? (!)
__________________
-ValC
ValC is offline
Reply With Quote
View Public Profile
 
Old 04-18-2005, 04:59 PM
ppedersen's Avatar
Super Talker

Posts: 115
Location: Tampa Bay, FL - USA
Trades: 0
Chrishirst got it right!

While chrishirst's code is for strings that CONTAIN "this", the other sample codes look for strings that ARE EXACTLY "this".
__________________

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
's Website
ppedersen is offline
Reply With Quote
View Public Profile
 
Old 04-18-2005, 05:08 PM
ppedersen's Avatar
Super Talker

Posts: 115
Location: Tampa Bay, FL - USA
Trades: 0
Quote:
Originally Posted by ValC
but the script u gave me returns this error
stripos only works in PHP 5. Most likely you have PHP 4. Try strpos instead. It works the same, except it is case-sensitive... while stripos is not.

If it has to be case-insensitive let us know... Some will give you the revised code.

Hope that helps
__________________

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
's Website
ppedersen is offline
Reply With Quote
View Public Profile
 
Old 04-18-2005, 05:45 PM
Average Talker

Posts: 29
Trades: 0
it works thanks alot!
__________________
-ValC
ValC is offline
Reply With Quote
View Public Profile
 
Old 04-18-2005, 06:25 PM
ppedersen's Avatar
Super Talker

Posts: 115
Location: Tampa Bay, FL - USA
Trades: 0
My pleasure...
__________________

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
's Website
ppedersen is offline
Reply With Quote
View Public Profile
 
Old 04-18-2005, 07:19 PM
Gaffer Sports's Avatar
Ultra Talker

Posts: 397
Name: Steve
Location: Scotland
Trades: 1
Quote:
Originally Posted by leavethisplace
complicating it a little
Quite surprised you never seen that he needed a tad more than a simple if statement, not like you.

Well done Chris & ppedersen.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
Gaffer Sports is offline
Reply With Quote
View Public Profile Visit Gaffer Sports's homepage!
 
Reply     « Reply to If X contains Y then ...
 

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 1.06433 seconds with 12 queries