Jump to content

[SOLVED] if any word in a field = something


jesushax

Recommended Posts

hi im after creating an if statment that will look up a field value and if a certain selection of words = something then execute code for example

 

FieldAnimal: 'dog''cat''mouse''bird'

 

if ($rs["FieldAnimal"] = dog) {code}

 

but obviously the field doesnt = dog

 

i need a way to find out if the field has dog init

 

any ideas?

 

thanks

 

Link to comment
https://forums.phpfreaks.com/topic/108808-solved-if-any-word-in-a-field-something/
Share on other sites

ok heres what i have, it doesnt work though

 


<?php 
$services = array($rsEdit["ClientServices"]);
?>  

  <table width="50%%" border="0">
    <tr>
      <td>XHTML/CSS Standards Compliant</td>
      <td><input type="checkbox" name="chkXHTML" value="XHTML/CSS Standards Compliant" class="blank" <?php if(in_array('XHTML/CSS Standards Compliant', $services)) {
echo 'checked="checked"';
} ?> /></td>

ok soo heres where im at, using your code above as guidelines this should work yes?

 

but it doesnt :(

 

$str = $rsEdit["ClientServices"];
$str = str_replace(":", "'", "$str");
$str = str_replace("''", "', '", "$str");
$services = array($str);
?>  
  <table width="50%%" border="0">
    <tr>
      <td>XHTML/CSS Standards Compliant</td>
      <td><input type="checkbox" name="chkXHTML" value="XHTML/CSS Standards Compliant" class="blank"
       <?php if(in_array('XHTML/CSS Standards Compliant', $services)) {echo 'checked="checked"';} ?> /></td>

 

echoing $str gives

 

'XHTML/CSS Standards Compliant', 'Webpage Design', 'Form to PDF/Email', 'Corporate Branding'

 

so why it no work?

 

cheers

Ok, I decided to go back to the original question, ignoring all the other posts (so I won't try to use someone else's code), and this is what I came up with to handle the problem stated:

<?php
function searchForThis($data, $search){
if (strstr($data, $search)){
	print "I found $search!";
}
else{
	print "$search was not found.";
}
}
/* Ok, lets take this function for a test spin: */
$data = "FieldAnimal: 'dog''cat''mouse''bird'";
$search = "mouse";
searchForThis($data, $search);
/* Ok, now that we have that result, lets try another */
/* First, lets give us some room.... */
print "<br />\n<br />\n<br />\n";
/* Ok, that's enough room */
$data = "This is a test (this one should fail)";
$search = "cheese";
searchForThis($data, $search);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.