tag:blogger.com,1999:blog-28244145696438685762024-03-18T02:47:57.556-07:00Programming TipsResearch on Ruby on Rails, JavaScript, CSS, HTML, Php and FlashUnknownnoreply@blogger.comBlogger120125tag:blogger.com,1999:blog-2824414569643868576.post-49436524358350455762015-05-20T19:04:00.000-07:002015-05-20T19:05:39.659-07:00PHP: Page pagination in arrayCode snippet:
<div class="box"><pre>$page = !empty( $_GET['page'] ) ? (int) $_GET['page'] : 1;
$total = count( $yourDataArray ); <font color="green">//total items in array</font>
$limit = 10; <font color="green">//per page</font>
$totalPages = ceil( $total/ $limit ); <font color="green">//calculate total pages</font>
$page = max($page, 1); <font color="green">//get 1 page when $_GET['page'] <= 0</font>
$page = min($page, $totalPages); <font color="green">//get last page when $_GET['page'] > $totalPages</font>
$offset = ($page - 1) * $limit;
if( $offset < 0 ) $offset = 0;
$yourDataArray = array_slice( $yourDataArray, $offset, $limit );
echo 'Pages: ';
for($i = 1; $i <= $totalPages; $i++){
if($i == $page){
echo '<b>' . $i . '</b> ';
}elseif($i != $page){
echo '<a href="testpage.php?page=' . $i . '">' . $i . '</a> ';
}
}
</pre></div>
Output:
<div class="box"><pre>Pages: <b>1</b> <a href="#" style="text-decoration: underline;">2</a> <a href="#" style="text-decoration: underline;">3</a> <a href="#" style="text-decoration: underline;">4</a>
</pre></div>
<br>
Refer: <a href="http://stackoverflow.com/questions/26451362/how-to-add-php-pagination-in-arrays" target="_blank">http://stackoverflow.com/questions/26451362/how-to-add-php-pagination-in-arrays</a>Unknownnoreply@blogger.com3tag:blogger.com,1999:blog-2824414569643868576.post-11329378015018089002015-05-19T20:16:00.001-07:002015-05-20T19:05:54.318-07:00PHP: Group array to unique valueExisting array:
<div class="box"><pre>Array
(
[0] => Array
(
[id] => 12
[name] => John
[description] => this is a description.
)
[1] => Array
(
[id] => 57
[name] => John
[description] => test description.
)
[2] => Array
(
[id] => 85
[name] => Amy
[description] => testing 123.
)
)
</pre></div>
Apply this:
<div class="box"><pre>$result = array();
foreach ($arr as $data) {
$name = $data['name'];
if (isset($result[$name])) {
$result[$name][] = $data;
} else {
$result[$name] = array($data);
}
}
</pre></div>
Output:
<div class="box"><pre>Array
(
[John] => Array
(
[0] => Array
(
[id] => 12
[name] => John
[description] => this is a description.
)
[1] => Array
(
[id] => 57
[name] => John
[description] => test description.
)
)
[Amy] => Array
(
[0] => Array
(
[id] => 85
[name] => Amy
[description] => testing 123.
)
)
)
</pre></div>
<br>
Refer: <a href="http://stackoverflow.com/questions/12706359/php-array-group" target="_blank">http://stackoverflow.com/questions/12706359/php-array-group</a>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-2824414569643868576.post-54051309258989015852014-03-04T19:51:00.001-08:002014-03-04T19:58:09.258-08:00PHP: Remove duplicate value in arrayBasic array:
<br />
<div class="box"><br />
<?php<br />
$input = array("a" => "green", "red", "b" => "green", "blue", "red");<br />
$result = <font color="red">array_unique</font>($input);<br />
print_r($result);<br />
?><br /><br />
</div>
Output:<br>
<div class="box"><pre>
Array
(
[a] => green
[0] => red
[1] => blue
)
</pre>
</div>
Refer site: <a href="http://sg3.php.net/array_unique" target="_blank">http://sg3.php.net/array_unique</a><br>
<br>
Multi-dimensional array:
<br />
<div class="box"><pre>
<?php
$date = array(
array('month' => 'Jan', 'year' => '2010'),
array('month' => 'Jan', 'year' => '2010'),
array('month' => 'Jan', 'year' => '2010'),
array('month' => 'Feb', 'year' => '2010'),
array('month' => 'Feb', 'year' => '2010'),
array('month' => 'Mar', 'year' => '2010'),
array('month' => 'Apr', 'year' => '2010'),
array('month' => 'Apr', 'year' => '2010')
);
print_r(<font color="red">super_unique</font>($date,'month'));
function super_unique($array,$key) {
$temp_array = array();
foreach ($array as &$v) {
if (!isset($temp_array[$v[$key]]))
$temp_array[$v[$key]] =& $v;
}
$array = array_values($temp_array);
return $array;
}
?></pre>
</div>
Output:<br>
<div class="box"><pre>
Array
(
[0] => Array
(
[month] => Jan
[year] => 2010
)
[1] => Array
(
[month] => Feb
[year] => 2010
)
[2] => Array
(
[month] => Mar
[year] => 2010
)
[3] => Array
(
[month] => Apr
[year] => 2010
)
)
</pre>
</div>
Refer site: <a href="http://stackoverflow.com/questions/307674/how-to-remove-duplicate-values-from-a-multi-dimensional-array-in-php" target="_blank">http://stackoverflow.com/questions/307674/how-to-remove-duplicate-values-from-a-multi-dimensional-array-in-php</a>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2824414569643868576.post-42981127158160319122014-02-19T23:51:00.001-08:002014-02-19T23:51:38.941-08:00Web Tools: Find Facebook IDFor integrations of certain Facebook social plugins, like the "Like" button and "Like box", and others, Facebook requires that you know your Facebook numeric user ID.
<br />
<br />
<iframe frameborder="0" height="350" src="http://findmyfacebookid.com/" width="550" style="border:1px solid #bbb;"></iframe>
<br />
<br />
Refer site: <a href="http://findmyfacebookid.com/" target="_blank">http://findmyfacebookid.com/</a>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-2824414569643868576.post-22895573339773935392014-02-09T19:47:00.002-08:002014-02-19T23:53:41.440-08:00Modernizr plugin: Progress button<b>Modernizr</b> is a JavaScript library that detects HTML5 and CSS3 features in the user's browser.
(Browser doesn't support: IE8 and below.)
<br />
<br />
<iframe frameborder="0" height="770" src="http://tympanus.net/Development/ProgressButtonStyles/" width="550" style="border:1px solid #bbb;"></iframe>
<br />
<br />
Refer site: <a href="http://tympanus.net/Development/ProgressButtonStyles/" target="_blank">http://tympanus.net/Development/ProgressButtonStyles/</a>Unknownnoreply@blogger.com12tag:blogger.com,1999:blog-2824414569643868576.post-74951286171458124772014-02-09T19:41:00.000-08:002014-02-19T23:53:54.273-08:00Modernizr plugin: Fullscreen overlay effect<b>Modernizr</b> is a JavaScript library that detects HTML5 and CSS3 features in the user's browser.
(Browser doesn't support: IE8 and below.)
<br />
<br />
<iframe frameborder="0" height="770" src="http://tympanus.net/Development/FullscreenOverlayStyles/index.html" width="550" style="border:1px solid #bbb;"></iframe>
<br />
<br />
Refer site: <a href="http://tympanus.net/Development/FullscreenOverlayStyles/index.html" target="_blank">http://tympanus.net/Development/FullscreenOverlayStyles/index.html</a>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-2824414569643868576.post-49824739183966359732014-02-06T02:18:00.000-08:002014-02-19T23:54:11.885-08:00jQuery Plugin: Better scroll on desktop and mobile device<iframe frameborder="0" height="700" src="http://areaaperta.com/nicescroll/demo.html" width="550" style="border:1px solid #bbb;"></iframe>
<br />
<br />
Refer site: <a href="http://areaaperta.com/nicescroll/" target="_blank">http://areaaperta.com/nicescroll/</a>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2824414569643868576.post-84043498309978778882014-02-04T23:56:00.000-08:002014-02-04T23:56:30.681-08:00PHP: Get Url Components<b>Example 1: Code</b><br />
<div class="box">
<br />
<?php<br />
$url = 'http://me:you@sub.site.org:29000/pear/validate.html?happy=me&sad=you#url';<br />
<br />
$output = parse_url($url);<br />
echo '<pre>' . print_r(parse_url($url), true) . '</pre>';<br />
echo 'Path: '.$output['path'];<br />
?><br />
<br /></div>
<br />
<b>Example 1: Output</b><br />
<div class="box">
<pre>Array
(
[scheme] => http
[host] => sub.site.org
[port] => 29000
[user] => me
[pass] => you
[path] => /pear/validate.html
[query] => happy=me&sad=you
[fragment] => url
)
Path: /pear/validate.html
</pre>
</div>
<br />
<b>Example 2: </b><br />
To retrieve just a specific URL component as a string:<br />
PHP_URL_SCHEME, PHP_URL_HOST, PHP_URL_PORT, PHP_URL_USER, PHP_URL_PASS, PHP_URL_PATH, PHP_URL_QUERY or PHP_URL_FRAGMENT<br />
<br />
<b>Code</b><br />
<div class="box">
<br />
<?php<br />
$url = 'http://me:you@sub.site.org:29000/pear/validate.html?happy=me&sad=you#url';<br />
<br />
echo parse_url($url, PHP_URL_PATH);<br />
?><br />
<br /></div>
<br />
<b>Output</b><br />
<div class="box">
<br />
/pear/validate.html<br />
<br /></div>
<br />
<b>Example 3: Code</b><br />
<div class="box">
<br />
<?php<br />
function parseUrl ( $url )<br />
{<br />
$r = '!(?:(\w+)://)?(?:(\w+)\:(\w+)@)?([^/:]+)?';<br />
$r .= '(?:\:(\d*))?([^#?]+)?(?:\?([^#]+))?(?:#(.+$))?!i';<br />
<br />
preg_match ( $r, $url, $out );<br />
<br />
return $out;<br />
}<br />
$output = parseUrl($url);<br />
echo '<pre>' . print_r($output, true) . '</pre>';<br />
echo 'Path: '.$output[6];<br />
?><br />
<br /></div>
<br />
<b>Example 3: Output</b><br />
<div class="box">
<pre>Array
(
[0] => http://me:you@sub.site.org:29000/pear/validate.html?happy=me&sad=you#url
[1] => http
[2] => me
[3] => you
[4] => sub.site.org
[5] => 29000
[6] => /pear/validate.html
[7] => happy=me&sad=you
[8] => url
)
Path: /pear/validate.html
</pre>
</div>
<br />
<b>Example 3: Explain output</b><br />
<div class="box">
<br />
$output[0] = full url<br />
$output[1] = scheme or '' if no scheme was found<br />
$output[2] = username or '' if no auth username was found<br />
$output[3] = password or '' if no auth password was found<br />
$output[4] = domain name or '' if no domain name was found<br />
$output[5] = port number or '' if no port number was found<br />
$output[6] = path or '' if no path was found<br />
$output[7] = query or '' if no query was found<br />
$output[8] = fragment or '' if no fragment was found<br />
<br /></div>
<br />
<b>Example 4: Code</b><br />
<div class="box">
<br />
<?php<br />
$url = 'http://me:you@sub.site.org:29000/pear/validate.html?happy=me&sad=you#url';<br />
<br />
echo 'SERVER_PROTOCOL: '.$_SERVER['SERVER_PROTOCOL'];<br />
echo 'SERVER_NAME: '.$_SERVER['SERVER_NAME'];<br />
echo 'SERVER_PORT: '.$_SERVER['SERVER_PORT'];<br />
echo 'PHP_SELF: '.$_SERVER['PHP_SELF'];<br />
echo 'REQUEST_URI: '.$_SERVER['REQUEST_URI'];<br />
?><br />
<br /></div>
<br />
<b>Example 4: Output</b><br />
<div class="box">
<br />
SERVER_PROTOCOL: HTTP/1.1 <br />
SERVER_NAME: sub.site.org<br />
SERVER_PORT: 29000<br />
PHP_SELF: /pear/validate.html<br />
REQUEST_URI: /pear/validate.html?happy=me&sad=you#url<br />
<br /></div>
<br />
<b>Example 5: Code</b><br />
<div class="box">
<pre>function getcurrentpath()
{ $curPageURL = "";
if ($_SERVER["HTTPS"] != "on")
$curPageURL .= "http://";
else
$curPageURL .= "https://" ;
if ($_SERVER["SERVER_PORT"] == "80")
$curPageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
else
$curPageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
$count = strlen(basename($curPageURL));
$path = substr($curPageURL,0, -$count);
return $path ;
}
echo getcurrentpath();
</pre>
<br /></div>
<br />
<b>Example 5: Output</b><br />
<div class="box">
<br />
If current URL is: <br />
http://www.abc.com/file/demo1/contact.html <br /><br />
Output will be: <br />http://www.abc.com/file/demo1/<br />
<br /></div>
Refer: <a href="http://blog.vivekv.com/php-get-the-current-url-path.html" target="_blank">http://blog.vivekv.com/php-get-the-current-url-path.html</a>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2824414569643868576.post-28558320146554727692014-01-02T01:23:00.000-08:002014-02-09T19:54:15.569-08:00Web Tools: Mobile + Tablet Device Dimensions<iframe frameborder="0" height="770" src="http://stefhatcher.com/projects/device-dimensions/" width="550"></iframe>
<br />
<br />
Refer site: <a href="http://stefhatcher.com/projects/device-dimensions/" target="_blank">http://stefhatcher.com/projects/device-dimensions/</a>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2824414569643868576.post-69589206439113000532013-07-22T19:59:00.001-07:002013-07-22T20:06:33.520-07:00CSS: Crop and resize image to certain ratioEdit <b>margin</b> and move the image around within the <b><div></b> container.
<br />
<br />
<div class="box">
<pre><style>
.crop {
width: 200px;
height: 150px;
overflow: hidden;
}
.crop img {
max-width: 400px;
height: auto;
margin: -75px 0 0 -100px;
}
</style></pre>
<pre><div class="crop">
<img src="http://img1.jurko.net/wall/paper/donald_duck_4.jpg" />
</div>
</pre>
</div>
<br />
<div style="text-align: center;">
<b><a href="http://jsfiddle.net/zWDUK/" target="_blank">Demo</a> </b></div>
<br />
Refer:<br />
<a href="http://stackoverflow.com/questions/493296/css-display-an-image-resized-and-cropped" target="_blank">http://stackoverflow.com/questions/493296/css-display-an-image-resized-and-cropped</a><br />
<a href="http://dabblet.com/gist/4711695" target="_blank">http://dabblet.com/gist/4711695</a><br />
<br />Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2824414569643868576.post-64882975708081004342013-01-07T07:14:00.000-08:002013-01-07T07:23:23.003-08:00PHP: Remove intersect element(s) in array<div class="box">
<pre>$array1 = array('abc', 'efg', 'hij', 'klm', 'nop', 'qrs');
$array2 = array('tuv', 'abc', 'wxyz', 'qrs', 'hij');
<span style="color: #38761d;">
// Find intersection</span>
$intersection = array_intersect($array1, $array2);
echo '<pre>'.print_r($intersection, true).'<span style="color: #38761d;"><span style="color: black;"></pre>';</span>
/* output:
Array
(
[0] => abc
[2] => hij
[5] => qrs
)
*/</span>
<span style="color: #38761d;">// Extract</span>
if(!empty($intersection)){
foreach ($intersection as $key => $value) {
unset($$array1[$key]);
}
}
echo '<pre>'.print_r($array1, true).'</pre>';
<span style="color: #38761d;">/* output:
Array
(
[1] => efg
[3] => klm
[4] => nop
)
*/</span>
</pre>
</div>
<br />
Refer site:<br />
Unset - <a href="http://sg2.php.net/manual/en/function.unset.php" target="_blank">http://sg2.php.net/manual/en/function.unset.php</a> <br />
Array intersect - <a href="http://php.net/manual/en/function.array-intersect.php" target="_blank">http://php.net/manual/en/function.array-intersect.php</a>Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-2824414569643868576.post-84690376787531610602012-11-01T23:51:00.000-07:002012-11-01T23:56:42.347-07:00Web Tools: Uncompressed JavaScript file Generator<iframe frameborder="0" height="730" src="http://jsbeautifier.org/" width="550"></iframe>
<br />
<br />
Refer site: <a href="http://jsbeautifier.org/" target="_blank">http://jsbeautifier.org/</a>Unknownnoreply@blogger.com46tag:blogger.com,1999:blog-2824414569643868576.post-2280415136500589192012-10-09T23:20:00.000-07:002012-10-10T00:05:14.393-07:00CSS: hasLayout hackClear float using "clear:both;"
<br />
<br />
<div class="box">
<pre><style>
ul {
list-style: none;
}
ul li {
float:left;
width:100px;
border:1px solid #ccc;
margin-right:5px;
text-align:center;
}
.clear {
clear:both;
}
.flower {
color:red;
font-weight:bold;
}
</style>
<ul>
<li>coffee</li>
<li>tea</li>
<li>water</li>
</ul>
<div class="clear"></div>
<div class="flower">rose</div>
</pre>
</div>
<br />
Add either width or height with a overflow hidden, it should cleared the float, without adding "clear:both;"
<br />
<br />
<div class="box">
<pre><style>
ul {
list-style: none;
<b>width:100%;
overflow: hidden;</b>
}
ul li {
float:left;
width:100px;
border:1px solid #ccc;
margin-right:5px;
text-align:center;
}
<span style="text-decoration: line-through;">.clear {
clear:both;
}</span>
.flower {
color:red;
font-weight:bold;
}
</style>
<ul>
<li>coffee</li>
<li>tea</li>
<li>water</li>
</ul>
<span style="text-decoration: line-through;"><div class="clear"></div></span>
<div class="flower">rose</div>
</pre>
<pre></pre>
<pre></pre>
<pre></pre>
</div><br />
Refer site: <a href="http://chatter.customdesigns.com.au/?p=123" target="_blank">http://chatter.customdesigns.com.au/?p=123</a>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2824414569643868576.post-20943743776756413262012-09-14T01:37:00.001-07:002012-09-14T01:37:52.727-07:00JavaScript: Array vs. Objects<table border="1">
<tbody>
<tr>
<th>Regular Array</th>
<th>Object/Associate Array</th>
</tr>
<tr>
<td><span style="color: #38761d;">// regular array (add an optional integer argument to control array's size)</span><br />
var myCars=new Array();<br />
myCars[0]="Saab";<br />
myCars[1]="Volvo";<br />
myCars[2]="BMW";
</td>
<td><span style="color: #38761d;">//Create a direct instance of an object</span><br />
personObj=new Object();<br />
personObj.firstname="John";<br />
personObj.lastname="Doe";<br />
personObj.age=50;<br />
personObj.eyecolor="blue";
</td>
</tr>
<tr>
<td><span style="color: #38761d;">// create literal array</span><br />
var myCars=["Saab","Volvo","BMW"];
</td>
<td><span style="color: #38761d;">//create alternative syntax (using object literals): </span><br />
personObj = {firstname:"John", lastname:"Doe", age:50, eyecolor:"blue"};
</td>
</tr>
<tr>
<td><span style="color: #38761d;">// find total length of array</span><br />
document.write(myCars.length);<br />
<span style="color: #38761d;">// output: 3
</span></td>
<td>Object.size = function(obj) {<br />
var size = 0, key;<br />
for (key in obj) {<br />
if (obj.hasOwnProperty(key)) size++;<br />
} <br />
return size;<br />
};<br />
document.write(Object.size(personObj));<br />
<span style="color: #38761d;">// output: 4
</span></td>
</tr>
<tr>
<td><span style="color: #38761d;">// print individual element of array</span><br />
document.write(myCars[0]);<br />
<span style="color: #38761d;">// output: Saab</span></td>
<td>document.write(personObj['firstname']);<br />
<span style="color: #38761d;">// output: John</span><br />
document.write(personObj.firstname);<br />
<span style="color: #38761d;">// output: John
</span></td>
</tr>
<tr>
<td><span style="color: #38761d;">// print all elements of array</span><br />
for(var x = 0; x < myCars.length; x++){<br />
document.write(myCars[x] + " ");<br />
}<br />
<span style="color: #38761d;">// output: Saab Volvo BMW
</span></td>
<td>var x;<br />
for (x in personObj)
{<br />
document.write(personObj[x] + " ");<br />
}<br />
<span style="color: #38761d;">// output: John Doe 50 blue
</span></td>
</tr>
</tbody></table>
<br />
Refer site:
<br />
<a href="http://www.w3schools.com/js/js_obj_array.asp">http://www.w3schools.com/js/js_obj_array.asp</a><br />
<a href="http://www.w3schools.com/js/js_objects.asp">http://www.w3schools.com/js/js_objects.asp</a>Unknownnoreply@blogger.com4tag:blogger.com,1999:blog-2824414569643868576.post-46586421657097120222012-05-02T01:23:00.000-07:002012-05-02T01:27:49.776-07:00JavaScript: Split a string and store into array<b>Example 1:</b>
<br />
<div class="box">
<pre><script type="text/javascript">
var myString = "123456789";
var mySplitResult = myString.split("5");
document.write("The first element is " + mySplitResult[0]);
document.write("
The second element is " + mySplitResult[1]);
</script></pre>
</div>
<b>Output 1:</b><br />
<div class="box">
<pre>The first element is 1234
The second element is 6789</pre>
</div>
<b>Example 2:</b><br />
<div class="box">
<pre><script type="text/javascript">
var cars = 'bmw,audi,honda,chrysler';
var split_cars = cars.split(',');
for (var i = 0; i < split_cars.length; i++) {
document.write(split_cars[i] + '
'); <span style="color: green;">// print all words</span>
}
</script></pre>
</div>
<b>Output 2:</b><br />
<div class="box">
<pre>bmw
audi
honda
chrysler</pre>
</div>
<br />
Refer site:<br />
<a alt="split string js" href="http://www.w3schools.com/jsref/jsref_split.asp" target="_blank">http://www.w3schools.com/jsref/jsref_split.asp</a><br />
<a alt="split string js" href="http://www.alexxoid.com/blog/dev/javascript-dev/how-to-explode-the-string-in-javascript.html" target="_blank">http://www.alexxoid.com/blog/dev/javascript-dev/how-to-explode-the-string-in-javascript.html</a>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-2824414569643868576.post-45180340037705847192012-03-26T14:37:00.000-07:002012-03-26T00:51:35.727-07:00PHP: Split string using array<b>Example 1:</b>
<br />
<div class="box">
<pre><?php
$str = "How are you doing today?";
$split_str = explode(" ", $str);
echo '<pre>'.print_r($split_str, true).'</pre>'; <span style="color: green;">// Output 1</span>
echo $split_str[1]; <span style="color: green;">// Output 2</span>
?></pre>
</div>
<b>Output 1</b>
<br />
<div class="box">
<pre>Array
(
[0] => How
[1] => are
[2] => you
[3] => doing
[4] => today?
)</pre>
</div>
<b>Output 2</b>
<br />
<div class="box">
<pre>are</pre>
</div>
<br />
<b>Example 2:</b>
<br />
<div class="box">
<pre><?php
$string = '<span style="font-weight: bold;">Lorem ipsum dolor sit amet:-</span><br>(1) consectetur adipisicing elit <br>(2) sed do eiusmod tempor <br>(3) incididunt ut labore et <br>(4) dolore magna aliqua';
echo '<p>'.$string.'</p>'; <span style="color: green;">// Output 3</span>
$chars = preg_split('/<br>/', $string, -1, PREG_SPLIT_OFFSET_CAPTURE);
$third_br_position = $chars[3][1];
$description = substr($string, 0, $third_br_position);
echo '<p>'.$description.'</p>'; <span style="color: green;">// Output 4</span>
?></pre>
</div>
<b>Output 3</b>
<br />
<div class="box">
<pre><b>Lorem ipsum dolor sit amet:-</b>
(1) consectetur adipisicing elit
(2) sed do eiusmod tempor
(3) incididunt ut labore et
(4) dolore magna aliqua</pre>
</div>
<b>Output 4</b>
<br />
<div class="box">
<pre><b>Lorem ipsum dolor sit amet:-</b>
(1) consectetur adipisicing elit
(2) sed do eiusmod tempor </pre>
</div>
<br />
Refer site:<br />
explode() - <a alt="split string php" href="http://php.net/manual/en/function.explode.php" target="_blank">http://php.net/manual/en/function.explode.php</a><br />
preg_split() - <a alt="split string php" href="http://php.net/manual/en/function.preg-split.php" target="_blank">http://php.net/manual/en/function.preg-split.php</a><br />
<a alt="split string php" href="http://www.java-samples.com/showtutorial.php?tutorialid=938" target="_blank">http://www.java-samples.com/showtutorial.php?tutorialid=938</a>
<br />
<br />Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2824414569643868576.post-61521274381670251942012-03-19T18:25:00.000-07:002012-05-27T19:53:47.328-07:00HTML: Automatically Fill in Email Subject (mailto)<b>Example 1: <a> tag</b>
<div class="box"><pre>
<a href="mailto:<b>emailname@yourdomain.com</b>?subject=<b>Subject You Selected</b>&body=<b>Body content</b>">The text of your link</a></pre>
</div>
<br>
<b>Example 2: open new window in JavaScript</b>
<div class="box"><pre>
window.open('mailto:<b>emailname@yourdomain.com</b>?subject=<b>Subject You Selected</b>&body=<b>Body content</b>');
</pre>
</div>
<br>
<b>Example 3: <form> tag</b> | (<a href="http://www.javascript-coder.com/files/email-form/javascript-email-form-example1.html">Demo</a>)
<div class="box"><pre>
<form action="<b>mailto:you@yourdmainhere.com</b>" method="post" enctype="text/plain">
FirstName:<input type="text" name="FirstName">
Email:<input type="text" name="Email">
<input type="submit" name="submit" value="Submit">
</form>
</pre>
</div>
<br>
Refer site: <br>
<a href="http://www.htmlbasictutor.ca/email-subject.htm" alt="Automatically Fill in Email Subject" target="_blank">http://www.htmlbasictutor.ca/email-subject.htm</a><br>
<a href="http://www.javascript-coder.com/javascript-form/javascript-email-form.phtml" target="_blank">http://www.javascript-coder.com/javascript-form/javascript-email-form.phtml</a>
<br />Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-2824414569643868576.post-68679613845252775232012-01-08T02:30:00.000-08:002012-05-24T23:25:56.214-07:00CSS: Image always stick to left/rightFile: <b>styles.css</b>
<div class="box"><pre><style>
.btn_right {
width: 50px;
height: 112px;
position: fixed;
right: 0pt;
top: 62px;
margin: 0px;
display: block;
}
.btn_left {
width: 50px;
height: 112px;
position: fixed;
left: 0px;
top: 50%;
margin: -45px 0px 0px;
cursor: pointer;
display: block;
}
.btn_close_right {
display: inline-block;
margin-left:30px;
width: 20px;
height: 18px;
background: url('close_icon.png') 0px 0px no-repeat;
cursor:pointer;
}
</style></pre>
</div>
<br />
File: <b>buttons.html</b>
<div class="box"><pre><link rel="stylesheet" type="text/css" href="styles.css" />
<font color="green"><!-- button always stick right --></font>
<div class="btn_right">
<img style="cursor:pointer;" src="btn_right.png">
<br>
<div class="btn_close_right"></div>
</div>
<font color="green"><!-- button always stick left --></font>
<div class="btn_left">
<img src="btn_left.png">
<br>
<img src="close_icon.png">
</div></pre>
</div>
<br />
Positioning Tutorial: <a href="http://www.barelyfitz.com/screencast/html-training/css/positioning/">http://www.barelyfitz.com/screencast/html-training/css/positioning/</a>Unknownnoreply@blogger.com5tag:blogger.com,1999:blog-2824414569643868576.post-70987087915629917392012-01-02T19:52:00.000-08:002012-09-14T03:13:17.021-07:00Web Tools: Online PHP script tester<iframe frameborder="0" height="950" src="http://codepad.viper-7.com/br1yF5" scrolling="no" style="border: 1px solid #eee;" width="100%"></iframe><br />
Refer: <a href="http://codepad.viper-7.com/br1yF5" target="_blank">http://codepad.viper-7.com/br1yF5</a>Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-2824414569643868576.post-5146396195193333492011-12-19T19:10:00.000-08:002015-05-20T19:18:35.561-07:00PHP: Simple Pagination in MySQL IFile: <b>booklist.php</b>
<div class="box"><pre><?php
<font color="green">// booklist.php?page=10</font>
$start_page = (empty($_GET['page'])) ? '0' : $_GET['page'];
function pagination(){
$sql = mysql_query("SELECT * FROM books ORDER BY id");
$result = mysql_num_rows($sql);
$counter = $result / 10;
$paginate = substr($counter, 0, strpos($counter, '.'));
for($i = 0; $i <= $paginate; $i++){
$pages = $i * 10;
$pg_num = $i + 1;
echo '<a href="booklist.php?page='.$pages.'">'.$pg_num.'</a> ';
}
return '<br />Total: '.$result;
}
$sql = mysql_query("SELECT * FROM books ORDER BY id LIMIT $start_page, 10");
<font color="green">// database fields</font>
$fields = "id,title,description,created";
$fields_array = explode(',',$fields);
<font color="green">// display</font>
echo '<table border="1">';
echo '<tr>';
foreach($fields_array as $key=>$field){
echo '<th>'.$field.'</th>';
}
echo '</tr>';
while($row = mysql_fetch_assoc($sql)){
foreach($fields_array as $key=>$field){
$field_name = (empty($row[$field])) ? '0' : $row[$field];
echo '<td align="center">'.$field_name.'</td>';
}
}
<font color="green">// pagination </font>
echo '<tr><td colspan="4">'.pagination().'</td></tr>';
echo '</table>';
?></pre>
</div>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-2824414569643868576.post-71269071649294559702011-12-17T00:47:00.000-08:002012-05-21T01:01:23.081-07:00Web Tools: Online "Loading" image Generator<div class="box"><img src="http://www.simonerodriguez.com/public/WindowsLiveWriter/FormSubmitinAjaxScriptperprincipianti_13F50/black_busy_1.gif" alt="" /><img src="http://www.simonerodriguez.com/public/WindowsLiveWriter/FormSubmitinAjaxScriptperprincipianti_13F50/bouncing_ball_16x16_1.gif" alt="" /> <img src="http://www.simonerodriguez.com/public/WindowsLiveWriter/FormSubmitinAjaxScriptperprincipianti_13F50/circle-ball-dark-antialiased_1.gif" alt="" width="16" height="16" /> <img src="http://www.simonerodriguez.com/public/WindowsLiveWriter/FormSubmitinAjaxScriptperprincipianti_13F50/circling-ball-3-frame-fade-black_1.gif" alt="" width="16" height="16" /> <img src="http://www.simonerodriguez.com/public/WindowsLiveWriter/FormSubmitinAjaxScriptperprincipianti_13F50/circling-ball-3-frame-fade-transparent-back-dark-antialiased_1.gif" alt="" width="16" height="16" /> <img src="http://www.simonerodriguez.com/public/WindowsLiveWriter/FormSubmitinAjaxScriptperprincipianti_13F50/circling-ball-black-back_1.gif" alt="" width="16" height="16" /> <img src="http://www.simonerodriguez.com/public/WindowsLiveWriter/FormSubmitinAjaxScriptperprincipianti_13F50/circling-squares-with-trail_1.gif" alt="" width="16" height="16" /> <img src="http://www.simonerodriguez.com/public/WindowsLiveWriter/FormSubmitinAjaxScriptperprincipianti_13F50/gray_busy_1.gif" alt="" width="29" height="5" /> <img src="http://www.simonerodriguez.com/public/WindowsLiveWriter/FormSubmitinAjaxScriptperprincipianti_13F50/green_rot_1.gif" alt="" width="24" height="24" /> <img src="http://www.simonerodriguez.com/public/WindowsLiveWriter/FormSubmitinAjaxScriptperprincipianti_13F50/hypnotize_out_1.gif" alt="" width="32" height="16" /> <img src="http://www.simonerodriguez.com/public/WindowsLiveWriter/FormSubmitinAjaxScriptperprincipianti_13F50/icon_animated_busy2_1.gif" alt="" width="16" height="16" /> <img src="http://www.simonerodriguez.com/public/WindowsLiveWriter/FormSubmitinAjaxScriptperprincipianti_13F50/icon_animated_busy2_2_1.gif" alt="" width="16" height="16" /> <img src="http://www.simonerodriguez.com/public/WindowsLiveWriter/FormSubmitinAjaxScriptperprincipianti_13F50/icon_animated_busy2_2_5_1.gif" alt="" width="16" height="16" /> <img src="http://www.simonerodriguez.com/public/WindowsLiveWriter/FormSubmitinAjaxScriptperprincipianti_13F50/icon_animated_busy_1.gif" alt="" width="16" height="16" /><img src="http://www.simonerodriguez.com/public/WindowsLiveWriter/FormSubmitinAjaxScriptperprincipianti_13F50/indicator.white_1.gif" alt="" width="16" height="16" /> <img src="http://www.simonerodriguez.com/public/WindowsLiveWriter/FormSubmitinAjaxScriptperprincipianti_13F50/kittscanner-transparent_1.gif" alt="" width="16" height="16" /> <img src="http://www.simonerodriguez.com/public/WindowsLiveWriter/FormSubmitinAjaxScriptperprincipianti_13F50/pleasewait_1.gif" alt="" width="214" height="15" /> <img src="http://www.simonerodriguez.com/public/WindowsLiveWriter/FormSubmitinAjaxScriptperprincipianti_13F50/progress_1.gif" alt="" width="10" height="10" /> <img src="http://www.simonerodriguez.com/public/WindowsLiveWriter/FormSubmitinAjaxScriptperprincipianti_13F50/progressBarLong_1.gif" alt="" width="100" height="16" /> <img src="http://www.simonerodriguez.com/public/WindowsLiveWriter/FormSubmitinAjaxScriptperprincipianti_13F50/progressBarShort_1.gif" alt="" width="50" height="16" /> <img src="http://www.simonerodriguez.com/public/WindowsLiveWriter/FormSubmitinAjaxScriptperprincipianti_13F50/radar-transparent_1.gif" alt="" width="16" height="16" /> <img src="http://www.simonerodriguez.com/public/WindowsLiveWriter/FormSubmitinAjaxScriptperprincipianti_13F50/expanding_circle_3.gif" alt="" width="32" height="16" /></div><br />
<iframe src="http://www.ajaxload.info/" frameborder="0" width="500" height="960" style="border: 1px solid #eee;"></iframe><br />
Refer site: <a href="http://www.ajaxload.info/">http://www.ajaxload.info/</a><br />Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2824414569643868576.post-52168780550966778662011-12-06T19:39:00.000-08:002012-05-03T19:42:26.137-07:00Web Tools: Online QR-Code Generator<iframe frameborder="0" height="510" src="http://qrcode.kaywa.com/" style="border: 1px solid #eee;" width="95%"></iframe><br />
<br />
Refer site: <a href="http://qrcode.kaywa.com/" target="_blank">http://qrcode.kaywa.com/</a>Unknownnoreply@blogger.com5tag:blogger.com,1999:blog-2824414569643868576.post-76806412068571868252011-10-30T03:02:00.000-07:002011-10-30T03:02:33.748-07:00<div class="qoute">
Computers are good at following instructions, but not at reading your mind. <span class="refer">~ Donald Knuth</span>
</div>Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-2824414569643868576.post-72307985180365510642011-10-29T02:48:00.000-07:002014-03-13T20:43:34.433-07:00PHP: Search URL in a stringWhen found an URL beginning with <b>http://</b>, add anchor tag to it.<br />
<b> </b><br />
<b>Code:</b><br />
<div class="box">
<pre><?php
$str = "bla http://www.example.com bla bla http://www.example.net bla bla";
$m = preg_match_all('<font color="red">/http:\/\/[a-z0-9A-Z.]+(?(?=[\/])(.*))/</font>', $str, $match);
if ($m) {
$links = $match[0];
for ($j = 0; $j < $m; $j++) {
$str = str_replace($links[$j],
'<a href="'.$links[$j].'">'.$links[$j].'</a>',
$str);
}
}
echo "Content: ".$str;
?></pre>
</div>
<br />
<b>Output:</b><br />
<div class="box">
<br />
Content: bla <a href="http://www.example.com/">http://www.example.com</a> bla bla <a href="http://www.example.net/">http://www.example.net</a> bla bla
<br /><br />
</div>
<br />
Refer: <br />
<a href="http://php.net/manual/en/function.preg-match-all.php" target="_blank" alt="function preg match all">http://php.net/manual/en/function.preg-match-all.php</a><br />
<a href="http://php.net/manual/en/function.preg-match.php" target="_blank" alt="function preg match">http://php.net/manual/en/function.preg-match.php</a><br />
<br>
Other regex expressions to match URL format:
<div class="box">
<pre><font color="red">@((https?://)?([-\w]+\.[-\w\.]+)+\w(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)*)@</font></pre>
</div>
Refer: <a href="http://stackoverflow.com/questions/16113652/using-phps-preg-match-all-to-extract-a-url" target="_blank">http://stackoverflow.com/questions/16113652/using-phps-preg-match-all-to-extract-a-url</a>
<br />
<br />Unknownnoreply@blogger.com14tag:blogger.com,1999:blog-2824414569643868576.post-37953948241593162542011-10-20T02:28:00.000-07:002011-10-29T02:22:38.869-07:00PHP: Convert Long Integer to StringSometimes long integer might automatic generate as a scientific notation/numerical format, when export to excel sheet for an example.<br />
Eg: <b>725239016523 --> 7.25239E+11</b><br />
<br />
To make sure all numbers are displayed, you may force the integer variable to string. There are many ways to convert it to string, below are some of the tricks, but might be more:-<br />
<br />
<div class="box">
<span style="font-size: small;"><?php</span><br />
<span style="font-size: small;">$integer = 725239016523;</span><br />
<span style="font-size: small;">echo $integer . " is a ". gettype($integer) . "<br>"; </span><span style="color: green; font-size: small;">// check type of $integer</span><br />
<span style="font-size: small;"><br /></span>
<span style="font-size: small;">$item = (string)$integer; </span><span style="color: green; font-size: small;">// or</span><br />
<span style="font-size: small;">$item = strval($integer); </span><span style="color: green; font-size: small;">// or</span><br />
<span style="font-size: small;">$item = trim($integer); </span><span style="color: green; font-size: small;">// or</span><br />
<span style="font-size: small;">$item = $integer.""; </span><span style="color: green; font-size: small;">// or</span><br />
<span style="font-size: small;">$item = $integer." "; </span><span style="color: green; font-size: small;">// or</span><br />
<span style="font-size: small;">$item = $integer."&nbsp;"; </span><span style="color: green; font-size: small;">// or</span><br />
<span style="font-size: small;">$item = "$integer"; </span><span style="color: green; font-size: small;">// or ...</span><br />
<span style="font-size: small;"><br /></span>
<span style="font-size: small;">echo $item . ' is a '. gettype($item) . "<br>"; </span><span style="color: green; font-size: small;">// check $integer whether is string or integer</span><br />
<span style="font-size: small;">?></span></div>
<br />
<br />
Refer: <a href="http://stackoverflow.com/questions/1035634/converting-an-integer-to-a-string-in-php" target="_blank">http://stackoverflow.com/questions/1035634/converting-an-integer-to-a-string-in-php</a><br />
<br />
See also check type of a variable<br />
<a href="http://php.net/manual/en/function.sprintf.php">sprintf()</a> - Return a formatted string<br />
<a href="http://sg.php.net/manual/en/function.gettype.php" target="_blank">gettype()</a> - Get the type of a variable<br />
<a href="http://sg.php.net/manual/en/function.is-bool.php" target="_blank">is_bool()</a> - Finds out whether a variable is a boolean<br />
<a href="http://sg.php.net/manual/en/function.is-float.php" target="_blank">is_float()</a> - Finds whether the type of a variable is float<br />
<a href="http://sg.php.net/manual/en/function.is-int.php" target="_blank">is_int()</a> - Find whether the type of a variable is integer<br />
<a href="http://sg.php.net/manual/en/function.is-string.php" target="_blank">is_string()</a> - Find whether the type of a variable is string<br />
<a href="http://sg.php.net/manual/en/function.is-array.php" target="_blank">is_array()</a> - Finds whether a variable is an array<br />
<a href="http://sg.php.net/manual/en/function.is-object.php" target="_blank">is_object()</a> - Finds whether a variable is an object<br />
<a href="http://sg.php.net/manual/en/function.is-numeric.php" target="_blank">is_numeric()</a> - Finds whether a variable is a number or a numeric string<br />
<a href="http://sg.php.net/manual/en/function.is-scalar.php" target="_blank">is_scalar()</a> - Finds whether a variable is a scalar<br />
<a href="http://sg.php.net/manual/en/function.is-null.php" target="_blank">is_null()</a> - Finds whether a variable is NULL<br />
<a href="http://sg.php.net/manual/en/function.is-resource.php" target="_blank">is_resource()</a> - Finds whether a variable is a resource<br />
<br />Unknownnoreply@blogger.com1