It adds an attribute to the SimpleXML element
Example
<?php
$xmlObj = simplexml_load_file(“test.xml”);
$xmlObj->client[0]->addAttribute(“ver”, “5”);
foreach($xmlObj->client[0]->attributes() as $a => $b) {
echo $a,’=”‘,$b,””</br>”;
}
?>
Output
ver=”5″
XML
<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<web>
<server>Apache</server>
<lan>PHP</lan>
<client>Javascript</client>
</web>
It creates a new SimpleXMLElement object.
Example
<?php
class PHPCode {
function __construct() {
print “Inside constructor”;
}
}
$phpObj = new PHPCode();
?>
Output
Inside constructor
It wraps a string into new lines when it reaches a specific length.
Example
<?php
echo wordwrap(“It wraps a string into new lines when it reaches a specific length”,5);
?>
Output
It wraps a string into new lines when it reaches a specific length
It return a formatted string
Example
<?php
echo vsprintf(“%s %s”,array(“php”,”code”));
?>
Output
php code
It output a formatted string
Example
<?php
vprintf(“%s %s”,array(“php”,”code”));
?>
Output
php code
It writes a formatted string to a specified output stream
Example
<?php
$file = fopen(“test.txt”,”w”);
echo vfprintf($file,”%s%s”,array(“PHP”,”Code”));
?>
Output
7
It converts the first character of each word in a string to uppercase
Example
<?php
echo ucwords(“php code”);
?>
Output
Php Code
It make a string’s first character uppercase
Example
<?php
echo ucfirst(“phpcode”);
?>
Output
Phpcode
It strips whitespace from the beginning and end of a string
Example
<?php
echo trim(” php code “);
?>
Output
php code
It returns part of a string
Example
<?php
echo substr(“phpcode”,2,4);
?>
Output
pcod
Zend | Magento Certified PHP | eCommerce Architect