I was working in a application which contained many “.svn” folder and so i wanted to delete all the folders at once so i fired this command
It will delete all the folders recursively
FOR /R . %f IN (.svn) DO RD /s /q %f
Ref
I was working in a application which contained many “.svn” folder and so i wanted to delete all the folders at once so i fired this command
It will delete all the folders recursively
FOR /R . %f IN (.svn) DO RD /s /q %f
Ref
At times you come across a scenario where the string contains an http link and you need to create the hyperlink to the same.
This is can very well achieved using the single line of code.
<?php
$text = "This is http://www.phpcoaching.in site";
echo $text = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a href=\"\0\" target=\"_blank\">\0</a>", $text);
?>
Source
many a times we need to fetch twitter updates on to our business website or elsewhere.
This is can very well achieved using the following lines of code.
<?php
$username='techoguru';
$format='xml';
$tweet=simplexml_load_file("https://api.twitter.com/1/statuses/user_timeline/{$username}.{$format}");
echo $text = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a href=\"\0\" target=\"_blank\">\0</a>", $tweet->status[0]->text);
?>
Source
Also if when we need to with our wordpress site
//Set parameter for query string
$username = 'techoguru';
$num = '10';
// Get the data from Twitter JSON API
$json = wp_remote_get("http://api.twitter.com/1/statuses/user_timeline.json?screen_name=$username&count=$num");
// Decode JSON into array
$data = json_decode($json['body'], true);
//Create unordered list
echo '<ul class="twitter">';
//Loop through all twitter tweets and display the text with the time it was created
foreach($data as $tweets)
{
$text = $tweets['text'];
$date = $tweets['created_at'];
//Make time human readable ie. 6 hours ago
$h_time = sprintf( __('%s ago'), human_time_diff( $time ) );
echo '<li>'.ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a href=\"\0\" target=\"_blank\">\0</a>", $text) . ' '. $h_time . '</li>';
}
//Close list
echo '</ul>';
Source
There is some times requirement to redirect naked URL to URL having “www”.
We have the solutions with our .htaccess file.
The following line of code will help us to achieve the purpose.
### re-direct to www
RewriteCond %{HTTP_HOST} ^phpblog.in
RewriteRule (.*) http://www.phpblog.in/$1 [R=301,L]
Today I was thinking of adding a favicon icon for my blog PHP Blog
For making favicon.ico file
<link rel="shortcut icon" href="<?php bloginfo('stylesheet_directory'); ?>/favicon.ico" />
Today I was asked to provide MYSQL version which we have used within our integrated system.
We as a developers are not bothered about the version, I was not aware of it and on my local system I have WAMP installed, so it directly gives the MYSQL version.
So to get MYSQL version from “mysql” command line, I got help from one of the site which asked to use the following line of code
select version ();
This will display the current MYSQL version used within system
To find no of checkboxes in html using jQuery or javascript
var inputs = document.getElementsByTagName("input"); //or document.forms[0].elements;
var cbs = []; //will contain all checkboxes
var checked = []; //will contain all checked checkboxes
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].type == "checkbox") {
cbs.push(inputs[i]);
if (inputs[i].checked) {
checked.push(inputs[i]);
}
}
}
var nbCbs = cbs.length; //number of checkboxes
var nbChecked = checked.length; //number of checked checkboxes
The following code gives no of check boxes present and no of checked.
Using the above code I have written following code
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
function chking()
{
/* For Running jQuery */
var cbs = $("input:checkbox"); //find all checkboxes
var nbCbs = cbs.size(); //the number of checkboxes
var checked = $("input[@type=checkbox]:checked"); //find all checked checkboxes + radio buttons
var nbChecked = checked.size();
/* For Running jQuery */
/* For Running Javascript */
var inputs = document.getElementsByTagName("input"); //or document.forms[0].elements;
var cbs = []; //will contain all checkboxes
var checked = []; //will contain all checked checkboxes
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].type == "checkbox") {
cbs.push(inputs[i]);
if (inputs[i].checked) {
checked.push(inputs[i]);
}
}
}
var nbCbs = cbs.length; //number of checkboxes
var nbChecked = checked.length; //number of checked checkboxes
alert(nbCbs);
alert(nbChecked);
/* For Running Javascript */
}
</script>
</head>
<body>
<form method="post" action="">
<input type="checkbox" name="cricket" value="cricket" /> cricket
<input type="checkbox" name="football" value="football" /> football
<input type="checkbox" name="hockey" value="hockey" /> hockey
<input type="checkbox" name="chess" value="chess" /> chess
<input type="checkbox" name="cards" value="cards" /> cards
<input type="button" value="check" onclick="chking();" />
</form>
</body>
</html>
Question
How to repeat a string n times in PHP?
Answer
<?php
echo str_repeat(" www.phpblog.in ", 3);
?>
Explanation
This function will repeat a particular string 3times and display on the screen
Answer:
To get the last element use the end()
<?php
$arr = array('php', 'online', 'tutorials');
echo end($arr); // tutorials
?>
How to define a variable in PHP?
<?php
define("ABC","Online Training");
echo ABC;//Online Training
?>
Also if I change the value of the variable at later stages what will happen
<?php
define("ABC","Online Training");
echo ABC;//Online Training
............
............
............
define("ABC","Online Training Institute");
echo ABC;//Online Training
?>
Even if we change the value it will display the previously set value only
Recent Comments