Category Archives: PHP

php news, php articals, php certification, php frameworks, php classes, php code, php feed, php update, php array, php string, php function, php oops, php xml, php open projects, PHP SOAP

How to explode a string and create hyperlink?

Here is very easy code to create Tagged List with hyperlink.
I have found several events where we have to create dynamic URL with Tagged text.
I have used very simple approach. Just Exploded sting and replaced space with “-”
You can use PHP function preg_replace() or str_replace() then used here-docs for creating hyperlink.
Instead of Echo Hear Docs is much better solution.
And at last removed the last Comma, and return your comma separated Dynamic links.

$tags = "jQuery Tutorials, PHP Display Errors, Drupal Module";
$tagL="";
function b2b_article_LinkedTags($stringTags) {
	$expTags = explode(",",$stringTags);
	foreach($expTags as $key=>$Tagevalue) {
	$Tagevalue = trim($Tagevalue);
	$link = preg_replace('/[^-a-z0-9]/', '-', strtolower($Tagevalue) );
	//$link = str_replace(" ","-", strtolower($Tagevalue));
	$tagL.=<<$Tagevalue,
EOF;
	}
	
	return substr($tagL, 0, -1);
}  
echo b2b_article_LinkedTags($tags)

Share

How to test HTTPS CURL in development server?

HTTPS is secure HTTP communication based on SSL protocol (HTTP over SSL). Generally all sensitive info (like passwords, financial details, etc.) are sent over this transport. Common example: your gmail login is done through HTTPS channel and different payment gateway.
So here in this deal –

$postfields = array('field1'=>'value1', 'field2'=>'value2');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://foo.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$result = curl_exec($ch);

CURLOPT_SSL_VERIFYHOST is off. This allows you to test the CURL in your dev server without having HTTPS. PHP/Curl will handle the http request.

Share

How to post XML using socket ?

I had discussed posting XML over HTTP using CURL in last post. Remember that was first method.
As I had promised on earlier post I would like to share second method with you. That is socket!!
Use this code and send your XML file.



1234567890
lgsoftwares
myapassword
phpmind.com





OGG
101009
';


$result = postXMLtoURL("www.yourdomain.com", "/path/",$xmlpacket);

$responseBody = getBody($result);

echo $responseBody;
?>

Share

How to post XML using CURL?

Recently I was working in a hotel booking engine and found a couple of methods to post XML to server; I thought this might be good to share with my friends who want to post xml via HTTP POST method.

There are several ways to Send XML requests via HTTP POST.
I am going to show you two ways. Both are very simple and easy.

As first approach I have used a small xml file with CURL.


'.
    ''.
        '1234567890'.
        'lgsoftwares'.
        'mypassword'.
        'phpmind.com'.
    ''.
    ''.
        ''.
        ''.
    ''.
''.
'JHM'.
        'OGGSHE'.
        '101009'.
        '101509'.
        '1'.
  ''.  
  '';


$URL = "https://www.yourwebserver.com/path/";

			$ch = curl_init($URL);
			curl_setopt($ch, CURLOPT_MUTE, 1);
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
			curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			$output = curl_exec($ch);
			curl_close($ch);

?>

Share

How to display certain number of words from a record?

I got good php tutorial to display certain number of words from database; in place of Database record you can use any other regular string.

 300) {
$ext = "... read more";
} else {
$ext = "";
}
function elliStr($s,$n) {
for ( $x = 0; $x < strlen($s); $x++ ) {
$o = ($n+$x >= strlen($s)? $s : ($s{$n+$x} == " "?
substr($s,0,$n+$x) . "..." : ""));
if ( $o!= "" ) { return $o; }
}
}

echo (elliStr("$text", 300)) . $ext;
?>
Share