Repeat the String  

<?php
echo str_repeat("S2k", 10);
?>
// here s2k repeat 10 times.
******* output ******
S2kS2kS2kS2kS2kS2kS2kS2kS2kS2k

[ add comment ] ( 1 view )   |  permalink  |   ( 3 / 36 )
Convert special characters to HTML entities 

<?php
$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
echo $new;
?>

********out put **********
// &lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt;

[ add comment ] ( 1 view )   |  permalink  |   ( 2.8 / 33 )
Join the all Array elemments in a single string in PHP 


<?php

$array = array('S2k', 'Design', 'Delhi');
$join_array = join(",", $array);
print "<pre>";
print_r ($array);
print "</pre>";
echo $join_array;

?>

//*************out put ***********
S2k,Design,Delhi

[ add comment ]   |  permalink  |   ( 3 / 20 )
change first letter of String in upper case in php 

<?php
$first = 'my name is rakesh';
$first = ucfirst($first); // Hello world!

echo $first;
?>

***********out put********

My Name is Rakesh

[ add comment ] ( 1 view )   |  permalink  |   ( 3.6 / 28 )
Change All charachter of string in Uppercase and Lowercase in PHP  


<?php
$str = "India is the best";
$str = strtoupper($str);
echo $str;
echo '<br>';
$str1 = "INDIA IS THE BEST";
$str1 = strtolower($str1);
echo $str1;
?>

**********
//output

INDIA IS THE BEST // All string to Uppercase

india is the best All string to Lowercase


[ add comment ] ( 1 view )   |  permalink  |   ( 3 / 20 )
Convert the HTML entities to their Decoded format  

<?php
$myhtml="I m &quot;the&quot; &lt;b&gt;best&lt;/b&gt; ";
$mydecode= html_entity_decode($myhtml);// out put comes like

echo $myhtml.'<br';
?>

**************Out Put ******

I m "the" <b>best</b>

[ add comment ] ( 1 view )   |  permalink  |   ( 2.8 / 33 )
Remove Space from right of the given text in PHP 

There are two function to remove space from right of the text:

(1) chop(string,"");
(2) rtrim(String,"");

//chop("yourstring ","");

<?php

$before='First ';
echo $before.'Second';
echo '<br>';
$after=chop($before," ");
echo $after.'raj'.'<br>';
?>

********* out put******

Rakesh raj // Before chop()
Rakeshraj // After chop()[ here white space removed from right of the

textx

[ add comment ] ( 1 view )   |  permalink  |   ( 3 / 20 )
CheckBox validation in HTML using Javascript 


<SCRIPT TYPE="text/javascript" LANGUAGE=JAVASCRIPT>

function validcheck() {
if (document.frmTest.chk1.checked == false &&
document.frmTest.chk2.checked == false &&
document.frmTest.chk3.checked == false)
{
alert (' Please Choose any one from the options.');
return false;
}
else
{
return true;
}
}

</SCRIPT>

********************
<html>
<body>
<form name="frmTest" onsubmit="return validcheck();" action="">
<input type="checkbox" name="chk1" value="India">India1</p>
<input type="checkbox" name="chk2" value="Pakistan">Pakistan</p>
<input type="checkbox" name="chk3" value="japan">japan</p>
<input type="submit" value="Submit!" />
</form>
</body>
</html>

[ add comment ] ( 1 view )   |  permalink  |   ( 3 / 15 )
Validate Email id with Regular Expression in Javascript 


<script>
function Validation(){

var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
str = document.getElementById('txtemail').value;
if(str.match(emailRegEx)) {
alert(str+' is valid email id.');
return true;
}
else {
alert(str+' is invalid email address.');
return false;
}
}
</script>

************************

<html>
<body>
<form name="frm" method="post" action="#" onsubmit="return Validation();">
Enter your email id:
<input type="text" name="txtemail" id="txtemail" />
<input type="submit" name="submit" value="Check"/>
</form>
</body>
</html>


[ add comment ] ( 1 view )   |  permalink  |   ( 3.8 / 24 )
Radio Button validation using Javascript in HTML 
This is very simple way to validate radio button through Javascript in HTML Form.



<script type="text/javascript">
function validate_form (str) {
valid = true;
if (
(document.frmSample.rdo1[0].checked == false )
&& ( document.frmSample.rdo1[1].checked == false ) )
{
alert ( "Please choose your option" );
valid = false;
}
else if( document.frmSample.rdo1[0].checked == true ) {
alert ( document.frmSample.rdo1[0].value );
valid=true;
}
else if( document.frmSample.rdo1[1].checked == true ) {
alert ( document.frmSample.rdo1[1].value );
valid=true;
}
}
</script>

***************************
<html>
<body>
<form name="frmSample" action="#" method="post" onSubmit="return validate_form();">
<input type="radio" name="rdo1" value="Male" />Male<br />
<input type="radio" name="rdo1" value="Female" />Female<br />
<input type="button" name="submit" value="Check" onClick="return validate_form();"/>
</form>
</body>
</html>


[ add comment ] ( 1 view )   |  permalink  |   ( 3 / 15 )

<<First <Back | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Next> Last>>