Friday, June 28, 2013

Manipulating Strings | PHP Function substr_replace( )

If you’ve ever programmed then you know how important is manipulating strings and similar. One of the good quality of PHP is that it offers many functions that can easily modify strings. Here I will present you one of most useful php function (by my opinion) for manipulating strings called substr_replace( ). It permits many kinds of string modifications.

substr_replace() syntax


The function replaces the part of original indicated by the start (0 means the start of the string) and length values with the string new. If no fourth argument is given, substr_replace( ) removes the text from start to the end of the string.
$string = substr_replace(original, new, start [, length ]);

Basic Example


$greeting = “good morning citizen”;
$farewell = substr_replace($greeting, “bye”, 5, 7);
Value of a variable $farewell is “good bye citizen”

Insert String Without Deleting

Use a length of 0 to insert without deleting
$farewell = substr_replace($farewell, “kind “, 9, 0);
Value of a variable $farewell is “good bye kind citizen”

Delete part of string

Use a replacement of “” to delete without inserting.
$farewell = substr_replace($farewell, “”, 8);
Value of a variable $farewell is “good bye”

Insert at the beginning of the string


Here’s how you can insert at the beginning of the string:
$farewell = substr_replace($farewell, “now it’s time to say “, 0, 0);
Value of a variable $farewell is “now it’s time to say good bye”‘

Negative start


A negative value for start indicates the number of characters from the end of the string from which to start the replacement:
$farewell = substr_replace($farewell, “riddance”, -3);
Value of a variable $farewell is “now it’s time to say good riddance”

Negative length


A negative length indicates the number of characters from the end of the string at which to stop deleting:
$farewell = substr_replace($farewell, “”, -8, -5);

Value of a variable $farewell is “now it’s time to say good dance”

Thursday, January 6, 2011

Convert Image To Text

Last time, Ivan wrote a tutorial to convert any image in to text format using PHP code. But that seems to have much friendliness with people having basic knowledge about coding. This time I researched in web if there are any free and small softwares that can do the job easily.

Shamelessly, I found it after 7 days of continuous search in several search engines, including Bing, Yahoo and Google. And you’ll be surprised to know that, this software is 11 years old. The original author of this tool is Steve Seymour.

Let’s have a look what it can do.

First of all download it from here.

You don’t need to install it, its an independent executable file.

The user interface is easily made and with no such hard turns. Click on Open image to load the image you want to convert to text. But make sure that the image is proper JPEG image.

Once the image is loaded, it will be displayed in the upper horizontal row. Below the right side of image, you can see the resolution and character numbers settings. This will determine the length of the characters in rows and columns. The lowest value 2 gives the highest possible resolution for the image. While the character’s size and resolution goes decreasing for the increasing value of 2+.

Once you are done with the image settings, click on Convert button to convert it to text.

The image will be converted to characters and you can easily copy or save it from Copy Text or Save Text button.

Paste it in any text editor, you’ll get the final result similar to the one below:

Monday, January 3, 2011

Defining a Function |PHP Tutorial For Beginners

Defining a Function |PHP Tutorial For Beginners

Posted: 12 Sep 2010 04:58 AM PDT

This is complete step by step tutorials that will help you learn basics about defining a PHP functions.


What is function?

A function is a named block of code that performs a specific task, possibly acting upon a set of values given to it, or parameters , and possibly returning a single value. Functions save on compile time no matter how many times you call them, functions are compiled only once for the page. They also improve reliability by allowing you to fix any bugs in one place, rather than everywhere you perform a task, and they improve readability by isolating code that performs specific tasks.


Function Syntax


To define a function, use the following syntax:

function [&] function_name ( [ parameter [, ... ] ] )
{
statement list
}


Example – sum of two numbers

Let’s take a look at a simple function. Example 1 takes two numbers, sum them, and then returns the result

function sum($number1, $number2)
{
$sumNumbers=$number1 + $number2 ;
return $sumNumbers;
}

?>

The function takes two arguments, $number1 and $number2. Using the + operator, the function sum the numbers in the variable $sumNumbers. Finally, we return the value $sumNumber.

How to call function sum?


echo sum(1, 2);

Output will be 3

or

$num1=1;
$num2=2;
echo sum($num1, $num2
);

Sunday, December 5, 2010

How To Bypass Surveys

You probably sometimes visit a great web site and then after a few seconds pop up annoying surveys . Damm…If you’re one of those who do not like to waste their time filling surveys then continue reading this article. Here I’ll show you several methods to bypass surveys.


NoScript 2.0.3

NoScript 2.0.3 is very useful add-on for firefox that can block almost everything , all types of surveys, pop-up ads and similar. It worth to have.


Download NoScript 2.0.3


SurveyBlock

SurveyBlock is service that allows you to view websites with “premium content” without having to fill out any gateway offers. Unfortunately , it isn’t free

Day Pass $3.99 USD
Monthly $8.99 USD (Promotional Price!)
Yearly $59.99 USD (Save 50%)

Visit http://surveyblock.com and sign up .


CPA Blocker 1.3

CPA Blocker 1.3 is add-on for firefox that automatically blocks popular survey popups. CPALock, Perfecttracking, Instant Dollarz, Dollarade, Adscend Media, Blvd-Media, and more. I tried this add-on but this didn’t work for me.

Downlaod CPA Blocker 1.3

Saturday, December 4, 2010

>> How To Create Simple Horizontal Navigation Bar From CSS >> How To Write Your First PHP Script

How To Create Simple Horizontal Navigation Bar From CSS

Posted: 10 Sep 2010 05:51 AM PDT

Though there are lots of tutorial about Horizontal listings, I founds lots of beginners having problem in understanding the mess of extra CSS codes added in it. There are several methods to achieve horizontal navigations.

One of them can be simply achieved by placing the sequence of links in a single line and styling it with CSS. Let’s see how to do this.

First of all, lets create a simple links arranged in a same horizontal line.

Home

About us

Portfolio

Contact us

Now when you save and load it in browser, it will look similar to the image below:

If you are satisfied with just these links in single line, then it is ok you can end the tutorial right here. Else if you want the horizontal navigation links like in Hackspc.com, you’ll have to follow up to the end of this tutorial.

We cannot easily create background effect in without using CSS. So, we’ll need to style it with proper CSS.

Now let’s apply some CSS to the link. But before applying any CSS to the tag, you must note that it must be specific to the horizontal links only. Otherwise, your other content links will also look same as the navigation links. So, let’s make it unique by keeping it inside a div with id menu.

Now we’ll define the compound CSS to so that the CSS style only applies to the link inside the MENU id.

Here is the simple CSS:

#MENU A {

Display:block;

Float:left;

Padding: 0 10px;

Background:#CCCCCC;

}

Now the above CSS will be applied to all the tags inside

. By default, tag is a inline tag that doesn’t makes extra spaces, in simple terms it is an object without a box. While blocks are the one which contains four sides, in simple terms it is an object inside a box.

Since, is not a block, we’ll have to manually make it block, this can be done by using display:block; property. Generally, block occupies full width that they can reach up to. So, whenever we create block, it takes whole width. Look at the image below.

In the above image, you can see that how blocks behaved by occupying the full width. Since, it appeared in different lines, it is not according to our interest. We want all these to appear in same line.

We’ll use CSS floats to appear it in same line. We’ll float these blocks to left. And this is what we have after applying floats.

You can see that, though it appeared in single line this time, it is not what we wanted. The clumsy appearance of the navigation links in the above image looks like it is the single image. We won’t press SPACE key to give some white space here. We’ll be using padding to left and right side to give a little bit space to it.

Let’s set padding of 10 pixels on both sides,

Padding: 0 10px;

We’ll get following results after padding.

Whoa! Finally it appeared in same line. But you might not find any good remarkable difference here with the first image of this tutorial.

At least, we’ve kept it in a box we can apply any CSS effect to it.

Let’s play with the background and border, remove underline and change link color to white,

background:#ccc;

border-left:1px solid #000;

text-decoration:none;

color:#fff;

This will be the result:

Now let’s apply some hover effect to it. To do so, we again have to specify the compound CSS to the links and add pseudo class, :hover to it.

#MENU A:hover {

Background:#00CCFF;

}

Simply we changed the background color to hex value #00CCFF. Now whenever the mouse is hovered the link box will be highlighted with a color.

The final CSS will look like this:

.MENU A {

display:block;

float:left;

padding:0 20px;

background:#ccc;

border-right:1px solid #000;

text-decoration:none;

color:#fff;

}

.MENU A:hover {

background:#0CF;

}

In next tutorial, we’ll see how we can use this method to lists. Till then stay tuned and bookmark us.

How To Write Your First PHP Script

Posted: 10 Sep 2010 05:26 AM PDT

You want to learn how to write PHP scripts but don’t know where to start from? In this tutorial I’ll show you all what you’ll need to write your first PHP script. It is a lot easier to get started with than you might think.


Why Use PHP?

PHP is a powerful tool for making dynamic and interactive Web pages.. By learning just a few simple functions, you are able to do a lot of things with your website. And once you know the basics, there are a wealth of scripts available on the internet that you only need to tweak a little to fit your needs


What you’ll need?

To start writing PHP scripts, you need access to a Web server running PHP.There are 2 options: to run php script on you web host or to run PHP script on your own computer .I recommend you second option to run PHP scripts locally, download XAMP and notepad++.

  • Run php script on you web host, if you have already your web host just upload php scripts on web server via FTP or file manager, if not then check this link Best Free Web Hosting, there you’ll find list of the best free web hosting, by my opinion. I recommend 000WebHost , all you need to do is register and you are ready to write you php scripts. The advantage of this approach is that you don’t have to install anything; the disadvantage is that it’s slower to write and test your script
  • Run PHP script on your own computer. There are many way to run php scripts locally , by my opinion the easiest way is to install a complete package like XAMPP. XAMPP is a great piece of software for a development machine, I highly recommend it. Be sure to have not start up when Windows starts, you can always turn it on manually when you need it. Here are detailed instruction How To Install XAMPP
  • Download text editor. To write PHP code you’ll need text editor, I recommend to download Notepad++ , here is download link


First PHP Script- Hello World.php

Every php script begins . Below is example of simplest Hello World php script. PHP command echo is a means of outputting text to the web browser.


How to upload php scripts on XAMPP?

Install XAMPP and launch it. Open text editor as notepad ++ type your code and save as filename.php.

Go to folder where you installed XAMMP, default it’s C:/xampp , there you’ll find folder called htdocs , save you script myFirstScript.php to htdocs

Launch your web browser and type http://localhost/myFirstScript.php


How to Upload PHP Scripts on 000webhost.com

Login to your 000webhost.com acc , open File manager

Go to folder public_html and click upload, browse your php script

Launch web browser and type http://yourDomainName.com/YourScriptName.php

Thursday, December 2, 2010

Create a unique headline animator from Feedburner using jQuery

Feedburner is one of the leading feed providers, now powered by Google. Unlike other feeding tools, feed burner provides large options to tweak your feeds post.By default, feedburner supports a beautiful Headline Animator which rotates through your latest posts in your feeds. If you have ever tried and played with headline animator, then you might have noticed that whenever you click in one of the post title, you’ll be redirected to the feeds home page instead of redirecting to the original post in your blog.

Alternative to this, Feedburner also provides BuzzBoost, which in real shows the list of your latest post with short excerpt. The title can be linked directly to your post rather than the feed homepage.

Now we’ll use the power of jQuery over BuzzBoost.

First of all look how the BuzzBoost initially looks when you first add it to your blog.

If you don’t know how to add BuzzBoost, then read the tutorial here.

Install BuzzBoost widget in any part of your website.

Now we’ll need to add jqeury effect to it.

Recently, I’ve posted a tutorial about world’s smallest jQuery based slideshow in my blog. I’ll be using same technique to animate the BuzzBoost.

See Today’s Headline BuzzBost Demo here how it looks when you are done.

Let’s see how we can apply this jQuery in BuzzBoost.

Copy the code shown below and paste it just above the code of BuzzBoost Code snippet.

script src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js' type='text/javascript'>
var x = 2;
function slideSwitch() {
var max=5
x += 1;
if (x > max) {
x = 1
}
$(".feedburnerFeedBlock ul li:nth-child(n)").animate({opacity:0});
$(".feedburnerFeedBlock ul li:nth-child(" + (x) + ")").animate({opacity:1});
}
$(document).ready(function() {
setInterval( "slideSwitch()", 5000 );
});