Php find word

SpaceshipSpaceship
Watch

NetworkTown.Net

Account Closed
Impact
2
Hi

I got a quick question how do i get php to find a word in my mysql result, like if in my result the $row['title']; has a work like football then i want to not show it, any way of doing that?
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
I would probably use:
PHP:
<?
$title = substr_count($row['title'], 'football');
if($title <= 0) {
//Show the stuff
echo "Heres Your Non-Football Results!";
} else {
//Don't Show The Stuff
echo "Heres Your Crappy Football...";
}
?>
 
0
•••
Can i deinfe more then one word like
PHP:
$title = substr_count($row['title'], 'football, ball, phone');
would that work?
 
0
•••
You could probably do:
PHP:
  <?
$checkfor = array("football", "ball", "phone");
$keepcount = 0;
foreach($checkfor as $value) {
$title = substr_count(strtoupper($row['title']), strtoupper($value));
$keepcount = $title+$keepcount;
}
if($keepcount <= 0) {
//Show the stuff
echo "Heres Your Non-Football or ball or phone Results!";
} else {
//Don't Show The Stuff
echo "Heres Your Crappy Football or ball or phone...";
}
?>

Thats how i do it, im not too good with preg_match etc so you may want to look into that as an alternative. I'm still learning as always :p

Check out the php.net manual regarding this str_count function http://uk.php.net/manual/en/function.substr-count.php
 
0
•••
You could try: (untested)
PHP:
<?php

$words = 'football|baseball|soccer'; // words separated by |
if (eregi('('.$words.')', $row['title'])) {
  // the title contains something in $words
} else {
  // the title doesn't have something in $words
}

?>
 
0
•••
Dan said:
You could try: (untested)
PHP:
<?php

$words = 'football|baseball|soccer'; // words separated by |
if (eregi('('.$words.')', $row['title'])) {
  // the title contains something in $words
} else {
  // the title doesn't have something in $words
}

?>

I told ya that i wasn't very good with all that preg and eregi stuff. Ill have to read up on it ^^ *clicks over to php.net*
 
0
•••
this eregi thing didnt work the way i wanted it to work, is there a mysql query that can find in my database any word, like if i want to find a row with the word ball in the description how would i do that?
 
0
•••
SELECT * FROM table WHERE field LIKE '%ball%'
 
0
•••
Dynadot — .com TransferDynadot — .com Transfer
Appraise.net

We're social

Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back