473,813 Members | 4,215 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there an operator to compare likeness in PHP?

Markus
6,050 Recognized Expert Expert
As you see in MySQL there is the "LIKE ='%something%'"

I was wondering if there was a way to do this within PHP?

Thanks :)
Nov 5 '07 #1
11 1537
code green
1,726 Recognized Expert Top Contributor
The closest is strstr() which searches for a string within a string
Nov 5 '07 #2
Motoma
3,237 Recognized Expert Specialist
The closest is strstr() which searches for a string within a string
I think a much nicer function to try is preg_match()! The only caveat is that you will need to use regular expressions.
Nov 5 '07 #3
tj111
12 New Member
Don't use regular expressions unless you need them. Regular expression take longer to run and use up more memory. I just replied to a convo about this earlier today, you can see my test results <LINK REMOVED>
Nov 5 '07 #4
Motoma
3,237 Recognized Expert Specialist
Don't use regular expressions unless you need them. Regular expression take longer to run and use up more memory. I just replied to a convo about this earlier today, you can see my test results <LINK REMOVED>
Compare both of those results to the amount of time for the request, round trip from handshake until the acknowledgment of the final packet. Add the execution times into the transfer time, and then give a final estimate on the difference in speed. I would be surprised if it was more than 10% overhead.
Additionally, you could include a version of your test which did a search for "toasty%sub " and see if, after the logic for the two combined searches complete, there is a performance difference which worries you.
Nov 5 '07 #5
Markus
6,050 Recognized Expert Expert
You make me feel soo self conscious about my progress with PHP.

I think my a-levels are going to have to reside in computing of some sort, so's i can catch up with you guys ¬_¬

Thanks for the replies and guidance!

:)
Nov 5 '07 #6
Markus
6,050 Recognized Expert Expert
While we're here,

i see things like this ALL over the place, i.e. email validation and such.

[php]
'/^[a-z]*$/'
[/php]

Anyone care to elaborate on what this is and does?

:)
Nov 5 '07 #7
Motoma
3,237 Recognized Expert Specialist
While we're here,

i see things like this ALL over the place, i.e. email validation and such.

[php]
'/^[a-z]*$/'
[/php]

Anyone care to elaborate on what this is and does?

:)
The ^ indicates the start of a string, the $ indicates the end of one. [a-z] represents all lowercase letters, while * indicates that there are no limits on the number of them. Therefore, that string used in preg_match will tell you whether or not the string is made only of lowercase alphabet characters.

Note: were the pattern string to contain an i after the final slash, it would perform a case-insensitive search, therefore upper and lowercase letters allowed.
Nov 5 '07 #8
Markus
6,050 Recognized Expert Expert
Ok, i'm starting to understand it :)

Thanks!
Nov 5 '07 #9
ak1dnar
1,584 Recognized Expert Top Contributor
tj111, I had to remove a link to another forum, from your post because posting such links, against our site rules. For further clarification please read the 6th point of "Things that are generally unacceptable" on FAQs. In future, It's better to discuss everything here at the same thread without pointing Other forum links. Still you can post links to good articles on other web sites, but NOT the forums links.
Thanks for your time.
Nov 6 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

5
1890
by: Peter Meier | last post by:
Hello everybody, Stroustrup says he prefer's to declare operators, which do not do anything on the class itself global. Does anybody know the reason for that? Any advantages/disadvantages? Thank you, Peter
5
2134
by: Teddy | last post by:
Hello all consider the class Date declaretion below: class Date { public: Date(); Date(int year, int month, int day); Date(const string&); int getYear() const;
14
4697
by: indigodfw | last post by:
Greetings from India I would like to know the rationale on allowing structs to be assigned (using = operator) and not allowing equality operator ( == operator) on them. The compiler when it assigns using = is aware of holes etc and the same compiler then should be able to generate code to compare the individual struct fields.
12
2212
by: cody | last post by:
Why can I overload operator== and operator!= separately having different implementations and additionally I can override equals() also having a different implementation. Why not forbid overloading of == and != but instead translate each call of objA==objB automatically in System.Object.Equals(objA, objB). This would remove inconsistencies like myString1==myString2
34
7191
by: Chris | last post by:
Is there ever a reason to declare this as if(*this == rhs) as opposed to what I normally see if(this == &rhs) ?
9
3749
by: marko | last post by:
/* code start */ int a = 0; /* expected evaluation and excution order with precedence in mind /* False(3) , True(1), False(2) */ if ( (a=1) == 0 || 0 != 1 && (a =2) == 1) putchar('T'); printf("%d", a); /* code end */ 2
10
4487
by: MasterGaurav \(www.edujini-labs.com\) | last post by:
Hi, I have a, probably very basic, query on value-types. Why cannot I use the == operator directly for value-types (not primitive types like int, float, double etc)? Why do I need to either have an implicit operator (to type-cast to primitive type) or override/overlaod the == operator myself?
12
2350
by: y-man | last post by:
Hi, I am creating a child class of the vector, which contains a couple of functions to make the work with carthesian coordinate vectors easier. To make things work more easily, I would like to be able to access the vector through a string which is either x, y or z. So that I can use: ---xyzvec.hh-- #ifndef XYZVEC_HH #define XYZVEC_HH
4
3062
by: Travis | last post by:
Is there a way to determine the percentage likeness two strings share? So that given an parameter string1 and a list of strings to search, I could display only those values that are say, a 75% or more match?
1
6714
by: Stuart Brockman | last post by:
Hi, I don't quite get what is going on in this code example: --------------------------- #include <iostream> using namespace std; class Base{ public:
0
10665
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10420
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9221
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7681
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5568
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5704
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3881
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.