Easy PHP

How to explode a string and create hyperlink?

Posted by 4 October, 2010 (0) Comment

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.=<<<EOF
	   <a href="./articles-tagged-$link">$Tagevalue</a>,
EOF;
	}
 
	return substr($tagL, 0, -1);
}  
echo b2b_article_LinkedTags($tags)
Share
Categories : Easy PHP,PHP Tags :

How to Stop SQL Injection in MYSQL?

Posted by 9 August, 2009 (4) Comment

Every PHP-MYSQL programmer need to know Anti-SQL Injection.

Please take a look at very simple function which can save your database!!

<?Php
 
function ClearInput($dirty){
 
	if (get_magic_quotes_gpc()) {
 
	$clean = mysql_real_escape_string(stripslashes($dirty));
 
	}else{
 
	$clean = mysql_real_escape_string($dirty);
 
	}
	return $clean;
 
}
 
?>
Share
Categories : Easy PHP,MySQL,PHP Tags :

How to Redirect with PHP?

Posted by 31 July, 2009 (0) Comment

You need to replace the URL above with the URL you wish to direct to.
Use this simple PHP script to redirect a user from the page they entered to a different web page.

<?php
header( 'Location: http://www.phpmind.com.com/blog/' ) ;
?>
Share
Categories : Easy PHP Tags :

How to display certain number of words from a record?

Posted by 15 May, 2009 (0) Comment

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.

<?php
$text = $row_recap['text'];
if (strlen($text) > 300) {
$ext = "... <a href='readmore.php'>read more</a>";
} 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
Categories : Easy PHP Tags :

How to remove HTML Tags from string?

Posted by 15 May, 2009 (5) Comment

If your strings have image code, any html code or DIV code you can easily remove using this code.

<?Php
$str = preg_replace("/<.*?>/", "", $str);
?>

Hope this little code will be useful for you.

Share
Categories : Easy PHP Tags :

How to display limited characters?

Posted by 15 May, 2009 (0) Comment

To display limited characters from database or from string there is a ready made function available in php it is called – substr ( string string, int start [, int length])

<?php
$mysite = "phpmind.com";
$string = substr($mysite, 0,7);
echo $string;
?>

Out put will be – phpmind

Share
Categories : Easy PHP Tags :

How to display random record with PHP AND MYSQL?

Posted by 15 May, 2009 (0) Comment

Here is very simple way to display random records from MYSQL using PHP.

View Code MYSQL
SELECT * FROM TableName ORDER BY RAND() LIMIT 0,1
Share
Categories : Easy PHP Tags :