Jump to content

Help Writing Conditional Statement


EK

Recommended Posts

I want to write a conditional statement like the following:

 

if ($value = "300x") {

 

however, I want this to work if x is changed to anything. So the conditional should work if the following is true:

 

if ($value = "300dog") {

 

or

 

if ($value = "300cat") {

 

How do I make it work as long as 300 is present regardless of what follows after. Thanks in advance!

Link to comment
Share on other sites

hi,

 

try this solution

 

<?php

$paragraph = '300 had not been then, greece would not have been now';
$paragraph1 = 'if 300 had not been then, greece would not have been now';
$var1 = '300';

if (stripos($paragraph, $var1)=='0') {
echo 'it works';
}
else {
echo 'it doesnt';
}

?>

 

now try changing $paragraph with $paragraph1 in stripos.

 

Regards,

Link to comment
Share on other sites

Thanks for the help. Actually my $var1 needed to be a string, something like 300var

 

So I changed

 

if (stripos($paragraph, $var1)=='0') {

 

to

 

if (stripos($paragraph, $var1) !== false) {

 

and it worked perfectly! Thanks!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.