Tặng sách lập trình Phpfox

Tặng sách lập trình Phpfox
Mình vừa viết xong một cuốn sách lập trình chuyền về mạng xã hội PHPFOX
Chi tiết tại http://giaoluutruonglop.vn/

Replace URLs in text with HTML links

function make_links_blank($text)
{
return preg_replace(
array(
‘/(?(?=]*>.+)
(?:
]*>.+)
|
([^=”\’]?)((?:https?|ftp|bf2|):\/\/[^ \n\r]+)
)/iex’,
‘/
]*)target=”?[^”\’]+”?/i’,
‘/
]+)>/i’,
‘/(^|\s)(www.[^ \n\r]+)/iex’,
‘/(([_A-Za-z0-9-]+)(\\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-]+)
(\\.[A-Za-z0-9-]+)*)/iex’
),
array(
“stripslashes((strlen(‘\\2’)>0?’\\1
\\2\\3′:’\’))”,
‘<a\\1',
'‘,
“stripslashes((strlen(‘\\2’)>0?’\\1
\\2\\3′:’\’))”,
“stripslashes((strlen(‘\\2′)>0?’\‘:’\’))”
),
$text
);
}

From :http://stackoverflow.com/questions/1188129/replace-urls-in-text-with-html-links

Find URLs in Text, Make Links

<?php

// The Regular Expression filter
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";

// The Text you want to filter for urls
$text = "The text you want to filter goes here. http://google.com&quot;;

// Check if there is a url in the text
if(preg_match($reg_exUrl, $text, $url)) {

// make the urls hyper links
echo preg_replace($reg_exUrl, "{$url[0]} “, $text);

} else {

// if no urls in the text just return the text
echo $text;

}
?>

Dạy lập trình PHP và Dạy lập trình mạng xã hội PHPFOX

Download PDF
Dạy lập trình PHPFOX

Download PDF
Dạy lập trình PHP

Liên hệ:
Nguyễn Thanh Nam
Email: khanhnam99@gmail.com
Phone: 0169 7540 418

Bán phần mềm quản lý dự án cho các công ty


Download PDF



Download PPT


Download PPT


Download DOC

Cung cấp cho các công ty cập nhật dự án trong tuần ,tháng năm.
Xem các dự án đã trúng thầu trong tháng ,trong năm.
Dễ dàng nhỏ gọn.

Liên hệ:
Nguyễn Thanh Nam
Email: khanhnam99@gmail.com
Phone: 0169 7540 418

Compressing CSS with PHP

function compress_css($css) {
    // Remove comments
    $css = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $css);
    // Remove whitespace
    $css = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), '', $css);
    return $css;
}
Dont’ forget that, if you are using PHP to output CSS, you’ll need to serve the correct headers:
header("Content-type: text/css");
header("Expires: " . gmdate("D, d M Y H:i:s", (time() + 604800000)) . " GMT");

get attr select option

<select name="test" id="test">
  <option value="1" title="something here"*>first option</option>
  <option value="2" title="something else here">second option</option>
  <option value="3" title="another thing here">third option</option>
</select>


$('#test option:selected').attr('title');

$('#test').find('option:selected').attr('title');

 

author

<?php
include ‘header.php’;
global $prefix;
$contact_firstname =$_GET[‘contact_firstname’];
$contact_lastname  =$_GET[‘contact_lastname’];
$user_price =$_POST[‘user_price’];
$user_expr  =$_POST[‘user_expr’];
//$id = base64_decode($_GET[‘user_email’]);
//$id = mysql_real_escape_string($id);
$id = base64_decode($_GET[‘user_email’]);
$kid =base64_encode(“$id|$user_expr”);
echo ” <div class=\”divct3\”>”;
//echo “<h1>Contact Form Submitted!</h1><br>”;
echo “<h1>Waiting…..</h1><br>”;

//echo “<span>We will be in touch soon.</span>”;

// This sample code requires the mhash library for PHP versions older than
// 5.1.2 – http://hmhash.sourceforge.net/

// the parameters for the payment can be configured here
// the API Login ID and Transaction Key must be replaced with valid values
$loginID        = “8a94AyWrDH7”;
$transactionKey = “2vkd94Fv54y43LK8”;
$amount         = “$user_price”;
$description     = “Transaction”;
$label             = “Submit Payment”; // The is the label on the ‘submit’ button
$testMode        = “false”;
//$testMode        = “true”;
// By default, this sample code is designed to post to our test server for
// developer accounts: https://test.authorize.net/gateway/transact.dll
// for real accounts (even in test mode), please make sure that you are
// posting to: https://secure.authorize.net/gateway/transact.dll
//$url            = “https://test.authorize.net/gateway/transact.dll&#8221;;
$url            = “https://secure.authorize.net/gateway/transact.dll&#8221;;

// If an amount or description were posted to this page, the defaults are overidden
if ($_REQUEST[“amount”])
{ $amount = $_REQUEST[“amount”]; }
if ($_REQUEST[“description”])
{ $description = $_REQUEST[“description”]; }

// an invoice is generated using the date and time
$invoice    = date(YmdHis);
// a sequence number is randomly generated
$sequence    = rand(1, 1000);
//$ID =”CUSID_”.$sequence;
// a timestamp is generated
$timeStamp    = time ();

// The following lines generate the SIM fingerprint.  PHP versions 5.1.2 and
// newer have the necessary hmac function built in.  For older versions, it
// will try to use the mhash library.
if( phpversion() >= ‘5.1.2’ )
{    $fingerprint = hash_hmac(“md5”, $loginID . “^” . $sequence . “^” . $timeStamp . “^” . $amount . “^”, $transactionKey); }
else
{ $fingerprint = bin2hex(mhash(MHASH_MD5, $loginID . “^” . $sequence . “^” . $timeStamp . “^” . $amount . “^”, $transactionKey)); }

// Create the HTML form containing necessary SIM post values
echo “<FORM method=’post’ name=’PayCharge’    action=’$url’ >\n”;
// Additional fields can be added here as outlined in the SIM integration guide
// at: http://developer.authorize.net
echo ”    <INPUT type=’hidden’ name=’x_login’ value=’$loginID’ />”.”\n”;
echo ”    <INPUT type=’hidden’ name=’x_amount’ value=’$amount’ />”.”\n”;
echo ”    <INPUT type=’hidden’ name=’x_description’ value=’$description’ />”.”\n”;
echo ”    <INPUT type=’hidden’ name=’x_invoice_num’ value=’$invoice’ />”.”\n”;
echo ”    <INPUT type=’hidden’ name=’x_fp_sequence’ value=’$sequence’ />”.”\n”;
echo ”    <INPUT type=’hidden’ name=’x_fp_timestamp’ value=’$timeStamp’ />”.”\n”;
echo ”    <INPUT type=’hidden’ name=’x_fp_hash’ value=’$fingerprint’ />”.”\n”;
echo ”    <INPUT type=’hidden’ name=’x_test_request’ value=’$testMode’ />”.”\n”;
echo ”    <INPUT type=’hidden’ name=’x_show_form’ value=’PAYMENT_FORM’ />”.”\n”;
echo ”  <input type=’hidden’ NAME=’x_cust_id’ VALUE=’$sequence’>”;
echo ”  <input type=’hidden’ NAME=’x_invoice_num’ VALUE=’$sequence’ >”;

echo ”  <input type=’hidden’ NAME=’x_email’ VALUE=’$id’ >”;

echo ”    <INPUT type=’hidden’ name=’x_receipt_link_method’ value=’LINK’ />”.”\n”;
echo ”    <INPUT type=’hidden’ name=’x_receipt_link_text’ value=’Click Here To Finish Your Payment’ />”.”\n”;
echo ”    <INPUT type=’hidden’ name=’x_receipt_link_url’ value=’http://www.controlmyfuturetoday.com/thankyou2.php?id=&#8221;.$kid.”‘ />”.”\n”;

echo”<input type=’hidden’  name=’x_first_name’ id=’x_first_name’ value=’$contact_firstname’/>”;
echo”<input type=’hidden’  name=’x_last_name’ id=’x_last_name’  value=’$contact_lastname’/>”;
echo”<input type=’hidden’  name=’x_country’ id=’x_country’ value=’US’ />”;

echo “</FORM>”;
echo”  <script language=\”javascript\”>
document.PayCharge.submit();
</script>”;

echo “</div>”;

include ‘footer.php’;

Cut word from content

function JCutWord($text,$num=20)
{
//  $text = eregi_replace(” +”, ” “,$text);
$text = preg_replace(“/ +/i”, ” “,$text);
$a=explode(” “, $text);

$count = count($a);
if($num > $count)
return $text;

$l=0;
for($i=0;$i<$num;$i++)
{
$l+=strlen($a[$i])+1;

}
return substr($text,0,$l).’…’;
// return substr($text,0,$l);
}

Cut html from content

function JNoHTML($str, $strip=””)
{
global $datafold;

/* The core of this code has been lifted from phpslash */

/* which is licenced under the GPL. */

if ($strip == “nohtml”)

$AllowableHTML=array(”);

$str = stripslashes($str);

//  $str = eregi_replace(“<[[:space:]]*([^>]*)[[:space:]]*>”,'<\\1>’, $str);
$str = preg_replace(“/<[[:space:]]*([^>]*)[[:space:]]*>/i”,'<\\1>’, $str);

// Delete all spaces from html tags .

//  $str = eregi_replace(“<a[^>]*href[[:space:]]*=[[:space:]]*\”?[[:space:]]*([^\” >]*)[[:space:]]*\”?[^>]*>”,'<a href=”\\1″>’, $str);
$str = preg_replace(“/<a[^>]*href[[:space:]]*=[[:space:]]*\”?[[:space:]]*([^\” >]*)[[:space:]]*\”?[^>]*>/i”,'<a href=”\\1″>’, $str);
// Delete all attribs from Anchor, except an href, double quoted.

//  $str = eregi_replace(“<[[:space:]]* img[[:space:]]*([^>]*)[[:space:]]*>”, ”, $str);
$str = preg_replace(“/<[[:space:]]* img[[:space:]]*([^>]*)[[:space:]]*>/i”, ”, $str);

// Delete all img tags

// $str = eregi_replace(“<a[^>]*href[[:space:]]*=[[:space:]]*\”?javascript[[:punct:]]*\”?[^>]*>”, ”, $str);
$str = preg_replace(“/<a[^>]*href[[:space:]]*=[[:space:]]*\”?javascript[[:punct:]]*\”?[^>]*>/i”, ”, $str);

// Delete javascript code from a href tags — Zhen-Xjell @ http://nukecops.com

$tmp = “”;

// repaire this line here
while (@ereg(“<(/?[[:alpha:]]*)[[:space:]]*([^>]*)>”,$str,$reg)) {
//  while (preg_match(“/<(/?[[:alpha:]]*)[[:space:]]*([^>]*)>/”,$str,$reg)) {
$i = strpos($str,$reg[0]);

$l = strlen($reg[0]);

if ($reg[1][0] == “/”) $tag = strtolower(substr($reg[1],1));

else $tag = strtolower($reg[1]);

if ($a = $AllowableHTML[$tag])

if ($reg[1][0] == “/”) $tag = “<$tag>”;

elseif (($a == 1) || ($reg[2] == “”)) $tag = “<$tag>”;

else {

# Place here the double quote fix function.

$attrb_list=delQuotes($reg[2]);

// A VER

$attrb_list = ereg_replace(“&”,”&amp;”,$attrb_list);

$tag = “<$tag” . $attrb_list . “>”;

} # Attribs in tag allowed

else $tag = “”;

$tmp .= substr($str,0,$i) . $tag;

$str = substr($str,$i+$l);

}

$str = $tmp . $str;

return $str;

exit;

/* Squash PHP tags unconditionally */

$str = ereg_replace(“<\?”,””,$str);

return $str;
}