PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > Newbie - is there a function similar to the sql 'like' comparisonoperator?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Newbie - is there a function similar to the sql 'like' comparisonoperator?

Réponse
 
LinkBack Outils de la discussion
Vieux 08/05/2008, 16h20   #1
revDAVE
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Newbie - is there a function similar to the sql 'like' comparisonoperator?

Newbie - is there a function similar to the sql 'like' comparison operator?

I would like to be able to compare 2 strings:

If $this ---*like or similar to*--- $that

That type of thing...


I know of this page:

http://us3.php.net/manual/sl/languag...comparison.php


But I don't see something 'like' or 'similar' to something else


--
Thanks - RevDave
Cool @ hosting4days . com
[db-lists]



  Réponse avec citation
Vieux 08/05/2008, 16h30   #2
Kalle Sommer Nielsen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Newbie - is there a function similar to the sql 'like' comparison operator?

Hi RevDave

Theres the similar_text() function which calculates the procentage of te
similarity between
two strings.

If your looking for a check to see if a string has some specified text then
use the strpos()
function and then the identical comparison operator to check for true and
false


Kalle Sommer Nielsen
DR - www.dr.dk

----- Original Message -----
From: "revDAVE" <Cool@hosting4days.com>
To: "PHP General" <php-general@lists.php.net>
Sent: Thursday, May 08, 2008 5:20 PM
Subject: [php] Newbie - is there a function similar to the sql 'like'
comparison operator?


> Newbie - is there a function similar to the sql 'like' comparison
> operator?
>
> I would like to be able to compare 2 strings:
>
> If $this ---*like or similar to*--- $that
>
> That type of thing...
>
>
> I know of this page:
>
> http://us3.php.net/manual/sl/language.operators.comparison.php
>
>
> But I don't see something 'like' or 'similar' to something else
>
>
> --
> Thanks - RevDave
> Cool @ hosting4days . com
> [db-lists]
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
>
>
> --
> No virus found in this incoming message.
> Checked by AVG.
> Version: 7.5.524 / Virus Database: 269.23.10/1421 - Release Date:
> 07-05-2008 17:23
>
>


  Réponse avec citation
Vieux 08/05/2008, 20h13   #3
Shawn McKenzie
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Newbie - is there a function similar to the sql 'like' comparisonoperator?

revDAVE wrote:
> Newbie - is there a function similar to the sql 'like' comparison operator?
>
> I would like to be able to compare 2 strings:
>
> If $this ---*like or similar to*--- $that
>
> That type of thing...
>
>
> I know of this page:
>
> http://us3.php.net/manual/sl/languag...comparison.php
>
>
> But I don't see something 'like' or 'similar' to something else
>
>
> --
> Thanks - RevDave
> Cool @ hosting4days . com
> [db-lists]
>
>
>

Probably the most similar that allows some wildcards (pattern matching)
is ereg(). You have more power in that you can control what must match
and how much.

In MySQL 'a' = ' a ' is true but 'a' LIKE ' a ' is false. So you need
to use the wildcard % to match anything ' xxaxx ' LIKE '%a%' is true or
_ to match one character ' a ' LIKE '_a_' is true.

The problem with similar_text() is that it gives you a percentage of
similarity which may be misleading unless you also figure in the return
of how many chars match. For example similar_text('CAT', 'CA', &$p) $p
would be 66.6%, is that like or not?

-Shawn
  Réponse avec citation
Vieux 09/05/2008, 09h56   #4
Colin Guthrie
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Newbie - is there a function similar to the sql 'like' comparisonoperator?

revDAVE wrote:
> Newbie - is there a function similar to the sql 'like' comparison operator?
>
> I would like to be able to compare 2 strings:
>
> If $this ---*like or similar to*--- $that
>
> That type of thing...


I strongly suggest you read up on regular expressions:
http://uk.php.net/manual/en/book.regex.php

Knowing how to use regular expressions is a a very handy skill. I do a
lot of mass changing of files via the command line with tools such as
grep, sed and awk and a mastery regular expressions can save hours of
laborious typing and find/replacing

Reminds me of one of my favourite xkcd cartoons:
http://xkcd.com/208/

Col

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 04h58.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11839 seconds with 12 queries