Blog Details

how to compare string in php


                                
                                    <h2>* PHP strncmp() Function :-</h2>
<ul>
	<li><span style="font-size: 13px;">The strncmp() function <strong>compares two strings.</strong></span></li>
	<li><b style="font-size: 13px;">Note:</b><span style="font-size: 13px;"> The strncmp() is binary-safe and case-sensitive.</span></li>
</ul>
&nbsp;
<h2>Syntax :</h2>
<strong>strncmp(<em>string1,string2,length</em>)</strong>

&nbsp;
<table>
<tbody>
<tr>
<td>
<h2><strong><em>string1</em></strong></h2>
</td>
<td>
<h2><strong>     Required. Specifies the first string to compare</strong></h2>
</td>
</tr>
<tr>
<td>
<h2><strong><em>string2</em></strong></h2>
</td>
<td>
<h2><strong>     Required. Specifies the second string to compare</strong></h2>
</td>
</tr>
<tr>
<td>
<h2><strong><em>length</em></strong></h2>
</td>
<td>
<h2><strong>     Required. Specify the number of characters from each string to be used in the comparison</strong></h2>
</td>
</tr>
</tbody>
</table>
<h2></h2>
<h2><strong>Return Value:</strong></h2>
&nbsp;
<h3><strong>        This function returns:</strong></h3>
<ul>
	<li>
<h3><strong>0 - if the two strings are equal</strong></h3>
</li>
	<li>
<h3><strong>&lt;0 - if string1 is less than string2</strong></h3>
</li>
	<li>
<h3><strong>&gt;0 - if string1 is greater than string2</strong></h3>
</li>
</ul>
<h3></h3>
<h3></h3>
<h2>Example :</h2>
&lt;html&gt;
&lt;body&gt;

<span style="color: #ff0000;">&lt;?php
echo strncmp("Hello","Hello",6);
echo "&lt;br&gt;";
echo strncmp("Hello","hELLo",6);
?&gt;</span>

&lt;/body&gt;
&lt;/html&gt;
<h2><strong>Output :</strong></h2>
<h2></h2>
0
-1
                                    


Categories

Core_PHP

Latest posts

13.05.14
Implementing CRUD Operations ¶

<ul> <li>Now comes the fun part. We would like t

13.05.14
View

<ol> <li><a href="http://www.yiiframework.com/do

13.05.14
Creating Model

<ol> <li><a href="http://www.yiiframework.com/do

Get Free Quote