PHP – Split sentence into words


Q.) Ignore ‘Spaces’ and split¬†sentence¬†into words and store into array

Function:

<?php
function splitIt($s){
			$arr = array('.',',');
			$s = str_replace($arr," ",$s);
			$s = preg_replace("/( )+/", " ", $s);
			$s = preg_replace("/^( )+/", "", $s);
			$s = preg_replace("/( )+$/", "", $s);
			$tokens = explode(" ",$s);
			return $tokens;
		}
?>

Input:

 <?php
 $answer = splitIt("   hello world. prt this sentence,please  ");
 print_r($answer);
?>

Output:

 Array ( 
    [0] => hello
    [0] => world
    [0] => prt
    [0] => this
    [0] => sentence
    [0] => please
)

W3Schools


[Tag::¬†At w3schools.com you can learn how to make a website. They offer free tutorials in all web development technologies. Learn¬†HTML,¬†PHP,¬†XML,¬†JavaScript,¬†SQL,¬†CSS,¬†HTML5,¬†Ajax,¬†JQuery,ASP.net,¬†Flash, Hosting….]

[My comment :: Want to learn web designing than you must check this website]

Website:: http://www.w3schools.com/

INFO:: W3Schools is a web developer’s portal, with tutorials and references relating to web development subjects, including HTML, XML, CSS, JavaScript,PHP, and SQL. W3Schools is free of charge, and is funded through text and display advertising. The tutorials and references on the website and the related code are proprietary. The site derives its name from the abbreviation for the World Wide Web; W3 is a numeronym of WWW.

Founded by:: It is created and owned by Refsnes Data, a Norwegian family-owned software development and consulting company.

PHP-MySQL Connection


For connecting to MySQL database, PHP offers several inbuilt functions and hence makes the work a lot easier.
mysql_connect()
mysql_close()
mysql_create_db()

to list a few. These are the most used functions for referring the database.
Here is the simple example:

$link = mysql_connect(‘localhost’, ‘mysql_user’, ‘mysql_password’);if (!$link) {

die(‘Could not connect: ‘ . mysql_error());

}

echo ‘Connected successfully’;

mysql_close($link);