String Equality: == Or Strcmp?

If I am trying to check if two strings are equal, would I ever run into problems by using == instead of strcmp?

Similarly, if I don't actually need to see which string is "greater" than the other, would == suffice?


String Compare Strcmp

I have a quick question about php strcmp The manual states the following Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal. PHP Code:

IF ( !strcmp ($str1, $str2 ) ){
    # DO WHAT EVER AND WHEN EVER both strings are exactly equal and strcmp = 0 or FALSE
    # DO WHAT EVER AND WHEN EVER strcmp is LESS than zero or GREATER then zero or TRUE as it were

View 1 Replies View Related

String Comparison == Vs Strcmp?

it seems that PHP's == operator is case sensitive? so is there any reason to use strcmp()? isit safe to do something like

if ( $password == $password2 ) { ... }

View 2 Replies View Related

Compare Two String Between Strcmp Functions?

why & what is the best method to compare two string between === and strcmp functions?

View 3 Replies View Related

Compare Two Objects For Equality

I've hit two problems recently that strike me as major issues. Firstly, if you compare two objects for equality, and there is some recursion involved internal to the object's structure, then PHP gives an error. Consider this:

$blob1 = new Blob ();
$blob2 = new Blob ();
$blob1->child = $blob2;
$blob2->child = $blob1;
$blob1 === $blob2 ? print 'equal' : print 'not equal'// works
$blob1 == $blob2 ? print 'equal' : print 'not equal'// fails
Class Blob
public $child;

I reported this as a bug, and was told "that's how PHP works not a bug" Secondly, today I find out that using session_start() is a good way to pass objects from web page to page, UNLESS they use SimpleXML.

View 7 Replies View Related

Malfunction Equality Operators

i have a html from that posts to a php-file in the php i have the following:

 if($_POST['name'] !== "") {
  // some echoing and mysql connecting code

at home everything works perfectly, but the stupid thing is that at my work, the if-statement ALWAYS executes, wether i post a name or not... Code:

View 2 Replies View Related

Equality Check Not Throwing Error

I just found the following code in a PHP script and was wondering why it didn't cause PHP to report an error?

$current_name == ($type != 3) ? $name : '' ;

It was a typo and the code was supposed to read:

$current_name = ($type != 3) ? $name : '' ;

View 2 Replies View Related

Testing Variable Equality In Twig?

In twig, is there an easy way to test the equality of 2 variables? {% if var1 = var2 %} isn't valid, {% if var1 is sameas(var2) %} only works if both are a strings... (from docs) "sameas checks if a variable points to the same memory address than another variable", like thats useful. So the only way I've found of comparing integers is to convert them both to strings: {% if var1|lower is sameas(var2|lower) %}

View 1 Replies View Related

Function With Equality Sign As Parameter?

variable declaration inside a definition of a function, like the one below. What's the purpose? The coding language I use is PHP.

function parse( $filename=FALSE ) {
//some code

View 5 Replies View Related

Check Equality Of $_SERVER['HTTP_REFERER'] ?

I have a PHP script that checks the HTTP Referer.

if ($_SERVER['HTTP_REFERER'] == '') {...}

However, this seems inherintly unsafe ... because what happens if the user goes toQuestion: what's a better equality test to ensure that the HTTP Referer is coming from

View 5 Replies View Related


For comparisons between strings, what's faster, the strcmp() function or the manual way (if ($x === $y) .. ). I've heard mostly that strcmp() is faster, just wanted confirmation from the experts here;).

View 1 Replies View Related

Strcmp Problem

I done a program to read text file, where content is

name: Juicy
age: 25
user text here

And I read the text file

$filename = "/usr/local/file/rpt.txt";
$fp = fopen($filename, 'r');

$content = fgets($fp);
while(strcmp($content,"@End@")<>0) {

$content = fgets($fp);

if(strcmp($content, "#Text#")==0){ //not match
$strPretext .= $content;
}//end if
//end while

I should get the data from #Text# until one line before @End@, but I get
nothing, I found that the strcmp for #Text# always not match when it read
through whole file.

View 1 Replies View Related

Strcmp Vs Equal

I noticed in some examples to the encrypt functions of the PHP manual a
syntax was used for password checks such as

if (strcmp($userpassword, md5($_POST['password'])) == 0) {
// do login

What is the advantage of this compared to

if ($userpassword == md5($_POST['password'])) {
// do login


View 5 Replies View Related

Strcmp Checking

I have a script that checks answers to a quiz in this fashion: Code:

if (strcmp($ques1, 'ques1answer')) {

However, I have one question that has two text fields, and both of them need to be correct in order to get the point. I tried this, but it didn't work:

if (strcmp($ques1a, 'answer1') & strcmp($ques1b, 'answer2')) {

Does anybody have an idea of what I could try?

View 6 Replies View Related

Case Sensitive Comparisons With Strcmp?

I've written a mod for phpBB to give the forum admin more control over
the smilies. Part of the mod checks to make sure that no two smilies
have the same code.

code = :), :-), :D, :P, :lol:, :happy:, etc.

For some reason my mySQL code is finding a match between :D and :d, :P
and :p, :cool: and :COOL:, etc. Other than that it works fine.

$sql = "SELECT smilies_id FROM " . SMILIES_TABLE . " WHERE
smilies_id!='" . $smilies_id . "' AND code=STRCMP(code, '" .
addslashes($code) . "')";

I've just noticed that I can get around this (sort of) by comparing the
filenames as well, ie. :D and :d would be linked to the same smiley.
But I'd still like to know why STRCMP (which is case sensitive) is
finding a match between D and d.

View 2 Replies View Related

Sort Array - Use Usort() And Probably Strcmp()

I have a drop down list that allows a user to select holidays and birthdays they've already entered into our database. The client asked that the user be able to sort this list alphabetically by holiday or birthday. I know I need to use usort() and probably strcmp() but I'm having trouble putting it together.


View 6 Replies View Related

Use Strcmp To Prevent Duplicate Log Lines?

I'm using the code below to compare the last line of a log minus the time stamp against $data, ive echo'd both of them and they are exactly the same however its still writing a new log entry every time. Am i missing something here? If the lines are the same it should break, if they aren't it should write a new entry.

$data = "This is a test."
$date = date("m/j : g:i A: ");
$lines = file('log.txt');
$last_line = $lines[count($lines)-1];


View 2 Replies View Related

Strcmp - Reorder A Array With Usort And Strcomp: Bug?

Using usort and strcomp together to order an array by one of its keys has an odd effect: it returns my array with fewer items in it than I put in.The array in my case contains rows representing tasks, and I want to order the rows in the array by the key 'displayorder', which is a number but which I want to be sorted in alphabetical manner (don't ask why).

function treeSort($a, $b) {

View 1 Replies View Related

Use Strcmp To Edit A Dynamically Generated Dropdown...

I've written a code that runs a 'SHOW DATABASES' query on my mysql server and lists the results(the names of the databases on my server) in a dynamically generated dropdown box, and it works just fine, using the following code:

echo "<select name='databaseselect'>";
$dblist = mysql_query('SHOW DATABASES');
while ($row = mysql_fetch_row($dblist)) {
echo "<option value='$row2[0]'>$row2[0]</option>";
echo "</select>";

The problem is that it lists ALL of the databases on my server - that's two of my own user-created databases, and the two default databases that come with the mysql server - 'information_schema' and 'mysql'. What I want to do is to, after running the 'SHOW DATABASES' query, eliminate those two databases from appearing in the dropdown box, because I don't want anyone to see them, as they're useless to anybody else. Code:

View 1 Replies View Related

Question On Using "strcmp" To Compare Unicode Strings

I am confused by the rule of comparing two unicode string using
function "strcmp". For exmaple, using "strcmp" to compare two Chinese uincode string, depending on what rule can "PHP" decide one string is greater or less
than the other string?

View 2 Replies View Related

Mysql Data - Retrieve The String From Beginning Till The Sub - String Discarding The Rest Of The String

I have Inserted a string containing a certain sub-string. What i want to do is retrieve the string from the beginning till the sub-string (without the substring) discarding the rest of the string following the sub-string.

View 8 Replies View Related

Replace Words Of A String Maintain Lowercase And Uppercase Chars Of Original String?

I have, for example, this string $string='Hello World, hello world'; I have a parameter in lowercase or uppercase and I need to replace all the equal words for <stong>word</strong> If i try this:


The result are Hello world, hello world (lowercase w in the first word) is to be possible replace string maintain lowercase and uppercase of the original string?

View 1 Replies View Related

String Manipulation To Remove Tokens From String And Assign The Result To A Variable?

Given the string variable in $widget_text...

$widget_text = '[widget_and-some-text]';

I need to do a string manipulation to end up with...

$widget_text_sanitized = 'and-some-text';

ie, I thought this should work:

$widget_text = trim($widget_text,'[]');
$widget_text_sanitized = str_replace('widget_','',$widget_text);

View 2 Replies View Related

Regex - Preg_match: Attempt To Match A String Where A Substring Does Not Exist In The String?

I have been trying to get this regex work. Suppose to parse an URL, if the string '_skipThis' is found, don't match the string. Also backreferences are needed too. For example:

String 1: a_particular_part_of_string/a/b/c/d/e/f
Result: preg_match should return true
Backreference: $1 -> a_particular_part_of_string, $2 -> /a/b/c/d/e/f

String 2: a_particular_part_of_string_skipThis/a/b/c/d/e/f

Result: preg_match should return false.

Backreference: nothing here.

I have tried the following regex..

reg1 = ([a-zA-Z0-9_]+)(/.*)
reg2 = ([a-zA-Z0-9]+(?!_skipThis))(/.*)
reg3 = ((?!_skipThis).*)(/.*)
reg4 = ((?!_skipThis)[a-zA-Z0-9_]+)(/.*)

View 2 Replies View Related

Double Forward Slash In A String Using Stripos() Will Not Match A String Even If It Is Present?

I ran into a little problem today when I was creating a really quick script to scan lines files in a user specified directory for //todo:. So I had a line like this:

if (stripos($data, '//todo:')) { //case-insensitive search ^^
//deal with the data appropriately

This did not find //todo: anywhere in any of the files! This was quite a surprise. I eventually ended up changing this line to remove the double forward slash (//) and it worked. Though this will now also match lines that are not comments that contain this string, perhaps not a common occurrence (and it'll likely never happen to me) but still possible.

View 2 Replies View Related

Encrypting A String With Blowfish In Ruby Returns A Shorter String Than The Same Process

When I try and use the following inputs to encrypt a string with Blowfish:

key = "some key"
input = "input string"

I get the following results:

ruby: ["79af8c8ee9220bde"]
php: 79af8c8ee9220bdec2d1c9cfca7b13c6

I am going to be receiving strings from a php application so I need to get these two to sync up but I don't understand why the php string would be longer. What am I missing?


View 5 Replies View Related

Remove <a> And All Other Html Tags From Tha Output String Not At The Time Of Input String?

I am wondering to know how it can be possible to remove the tags from output string in PHP. At the time of input It can be removed by strip_tags() that I know but From already generated output where html tags appeared, How it can be removed ?

For example :

<p>Test paragraph.</p> <a href="#fragment">Other text</a>


I have pointed what i am getting from database. Its like static text.This is the output string appearing in my blog description. I want to remove html tags from the string. How can i be removed.

View 1 Replies View Related

Collect Form Data, Use Variables, Concatenate Into String And Fopen String?

I currently have a PHP file that already includes variables such as 'username' and 'password' (for authentication), but I would like to collect the form data submitted,  concatenate everything into one string, and then open up this string (which is essentially a url)

I undrstand (with thanks to schme16) that I have to use
$_POST['name_of_form input']
to retrieve the data, but after that I would like to put all of these into one string that looks like$username&password=$password&msg=$message

and then use fopen to load this url.

View 6 Replies View Related

Enter The Decrypted String Into A Text Field And It Outputs The Decypted String?

Ok, so there are two functions, one encrypts data, the other one must decrypt. But I do not know how to implement it to decrypt. I need to know how to use the second function (number_decrypt). I need it so I enter the encrypted string into a text field and it outputs the decypted string. I dont need the html, I just dont understand how to implement it.

Heres the code:

View 1 Replies View Related

Image Processing - Measuring A String - Return The Width In Pixels Of A String Given A Certain Font / Size?

ASP has a MeasureString function that returns the width, in pixels, of a string given a certain font/size. Is this possible in PHP?

View 2 Replies View Related

Regex Match Multiple String Combinations Inside A String And Remove Unwanted Letters Between All Matches

I have a string with several lines of CSS code. I want to match all occurences of :

background:url(" url ");

and remove everything except the filename. Example input:


View 1 Replies View Related

Copyrights 2005-15, All rights reserved