String Equality: == Or Strcmp?

Jun 16, 2005

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

Jul 19, 2007

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?

Jul 26, 2010

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?

Jan 19, 2010

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

View 3 Replies View Related

Compare Two Objects For Equality

Mar 1, 2007

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

Oct 13, 2007

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

Jul 6, 2011

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?

Nov 29, 2010

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?

Dec 16, 2010

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'] ?

Apr 5, 2010

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


May 3, 2004

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

Mar 27, 2006

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

Jul 17, 2005

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

Sep 4, 2007

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?

Jul 17, 2005

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()

Jan 8, 2010

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?

May 23, 2011

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?

Aug 12, 2010

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

Mar 29, 2007

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

Jul 17, 2005

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

May 11, 2009

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?

Feb 17, 2011

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?

Mar 25, 2011

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?

Sep 27, 2010

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?

Jun 24, 2010

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

Mar 28, 2011

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?

Apr 20, 2011

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?

Aug 27, 2007

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?

Oct 21, 2010

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?

Jul 1, 2010

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

Nov 17, 2010

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

Arrays - Combine Two String / Store Full String Into Database?

Apr 10, 2011

I have two stings

a, b, d, e


1, 52, 34, 56

I want combine two strings as

a/1, b/52, d/34, e/56

I wrote my code like that:-

$result2 = mysql_query($query2);
$arr2 = explode(",",$row2['string1']);
$arr1 = explode(",",$row2['string2']);
for($i2 = 0; $i2 < count($arr1); $i2++) {
$raw_str = "".$arr2[$i2]."/".$arr1[$i2].",";
$query3 = "UPDATE table SET com_str='".$raw_str."' WHERE id='".$row2['id']."'";
if (!mysql_query($query3))
die('Error: ' . mysql_error());

my code just can store a last value only into databese:-


But I want store full string into database.

View 4 Replies View Related

Function That Converts String Containing Normal Text To String For URLs?

Jul 6, 2011

For example: Mary has 50$ and 34. If I paste this in the browser address bar I get redirected to Google and the URL contains: Mary+has+50$+and+34 E2 82 AC. Is there a PHP function that is able to do this? I want to pass a string to a URL in curl and need to make it look like this, so it doesn't break anything

View 5 Replies View Related

Error - Encoding: String '00127920110531 Xxx Zzz Dom 67 Av Renxe9...' Is Not A Valid Utf-8 String

Jun 10, 2011

I'm using Zend Soap Server with autodiscover, this is my code:

$wsdl = new Zend_Soap_Autodiscover();
if (isset($_GET['wsdl'])) {


When I invoke some methods through a SOAP client, I receive this error:

SOAP-ENV:ServerSOAP-ERROR: Encoding: string '00127920110531 xxx zzz Dom 67 av Renxe9...' is not a valid utf-8 string

the "xe9" is a "é"... source table is in UTF-8 if I change




i don't receive the error but the strings aren't correctly parsed, there are stranges chars...

View 1 Replies View Related

Necessary To Concatenate The String If Start A New Line While Writing A String In Source?

Jul 7, 2010

I'm learning PHP and MySQL together from Head First PHP & MySQL and in the book, they often split their long strings (over 80~ characters) and concatenate them, like this:

$variable = "a very long string " .
"that requires a new line " .
"and apparently needs to be concatenated.";

I have no issue with this, but what strikes me odd is that whitespace in other languages usually don't need concatenation.

$variable = "you guys probably already know
that this simply works too.";

I tried this and it worked just fine. Aren't line breaks always interpreted with a space at the end? Even the PHP manual doesn't concatenate in the echo examples if they span over one line. Should I follow my book's example or what? I can't tell which is more correct or "proper" since both work and the manual even takes a shorter approach. I also would like to know how important is it to keep code under 80 characters in width? I have always been fine with word warp since my monitor is pretty large and I hate my code getting cut short when I have the screen space.

View 5 Replies View Related

Create Unique Alpha Numeric String For An Input String / Url?

Oct 20, 2009

I want to create a less than or equal to 10 character unique string for an input string which could be a url


OR an alpha numeric string


but the result should be unique for every input...Is their any function or class that you use for your projects in php.

View 2 Replies View Related

Search String Depending On Keywods In String - Finding Out Labels

Jul 13, 2011

I want to develop a mechanism for search, but I have some requirements for it. I am not getting where should I start. For example I have to search this string

stringToSearch = 'I have to search something';

For that I am going to add some labels to certain keywords at start. suppose Messi will come under football, and Rain will come under Weather and Search will come in Search Engine, Google, Like that so I have Labels for keywords in short and it could be possible that one keyword is in multiple labels. Now when I am searching some string I do have to calculate best labels for it and I want to do it on the basis of criteria mentioned below. I will add keywords to labels on the basis of user answering a search string belongs to which label (User u can take here as a answering agents who will chose their labels so that question of particular labels come to them) Every time keywords match will be counted. If more than one keywords in a string belongs to one labels then select that labels as relevant one.

View 1 Replies View Related

Generate String With Apostrophe After Each Letter Of Original String In Turn?

Jul 30, 2009

How can I iteratively create a variant of "Murrays" that has an apostrophe after each letter? The end-result should be:


View 5 Replies View Related

MD5 Of String In ActionScript Returning Incorrect Results When Some Hex Is Part Of The String?

Feb 8, 2010

I am trying to MD5 a string in ActionScript using the MD5 algorithm that was created by Adobe and is part of AS3corelib.[URL]....I am comparing this to an MD5 created in php that I know is correct.If I create MD5s using AS and PHP for say a string like "abcd1234" they both are equal, as is to be expected. The problem is, when my string contains some hexadecimal in it ie "abcdx28xBFx4E", the MD5s from ActionSCript and php return different value. Now the really strange part is as long as the hexadecimal is in the form of a number when its a string its fine and still matches:


View 2 Replies View Related

Debugging - View The Actual $string Processed By File_get_contents($string)

Sep 10, 2010

I'm forced to use an older version of php on a server, and it seems to have a bug in the function file_get_contents(); I believe it's a bug because the issue doesn't happen on the current version of php.

$string = 'intraneturl/?really_long_example_query_parameters';

When I pass the $string into file_get_contents($string); the part with the query parameters seems to get truncated at some point because the returned information is different than when I run the exact same code on the up-to-date version of php on my dev machine.

My question is: How can I see the exact string that file_get_contents(); processed. I know what I sent in, but I don't believe it's processing it as I sent it. There may be a generic answer for viewing the innards of all functions via debugger or something. Do I need to use a debugger or is there a way to just print the information on the screen?

View 1 Replies View Related

String Returned By Variable Not Working Like The Same String Entered Manually?

Apr 2, 2011

I am trying to make some adjustments to uploadify.php which comes with the latest version of uploadify (3.0 beta), so that it works with a session variable that stores the login username and adds it to the path for uploads. Here is uploadify.php as it currently looks:

Code: [Select]<?php


I added Code: [Select]echo $targetFolder; at the bottom so that I could make sure that the string returned was correct, and it is, i.e. '/songs/nick'. For some reason though, uploads are not going to the correct folder, i.e. the username folder, but instead are going to the parent folder 'songs'. The folder for username exists, with correct permissions, and when I manually enter Code: [Select]$targetFolder = '/songs/nick';all works fine. Which strikes me as rather strange. I have limited experience of using php, but wonder how if the correct string is returned by the session variable, the upload works differently than with the manually entered string.

View 1 Replies View Related

Replace String And Code Echos The Line Without The Replaced String And With It?

Apr 5, 2011

I need to break down this statement. I have tried to replace string and my code echos the line without the replaced string and with it. I don;t think that str_replace is how to do what I want to do.



View 2 Replies View Related

Attaching A String To A Normal Word Without Loosing The String

Sep 13, 2003

In my database I have content rows that are either called <contentname>_title or <contentname>_fulltext. now when someone clicks a link on the site it goes to index.php?action=<contentname> so I guess you see where im going..

when someone goes to such a section index.php sees $action is used and attaches it to _title and _fulltext, so u get: $action_fulltext.. basicly of cuz php now sees it as one string '$action_fulltext' and not '$action'_fulltext.

View 3 Replies View Related

String -> String That Is Compatible With Linux File System.

Jul 17, 2005

Does a function excist that converts a string to a string thats compatible
with linux file system?

View 3 Replies View Related

String Manipulation - Round String Off To The Nearest Number

Oct 30, 2005

this is going to be real easy i think but i just cant do it. I have a query that sends me back an answer like &#393;.2'. I want to either round it off to the nearest number, i.e 3 and/or add a zero to the end if it has a '.' in it and or get rid of the '.'

View 1 Replies View Related