PHP Help By A Noob For Noobs

This help page includes complete PHP code which should work on any system with PHP installed.
If your using Windows when specifying system folders you must use '\\' instead of the '/' shown in this help.

Click Anything Highlighted Green To Find Out About That Function

If You Require Somewhere To Use PHP Contact Us On Link At Bottom Of Page & We Will Email You With Details To A Server With Help On How To Use It.


Downloading A Website & Retrieving Data You Wish To Access.
Below Code Will Create A List Of Chatrooms On Demo Site Given

<?PHP
$url = "http://spcn.io/ChannelsList";
//This is just a random sites link i had handy for this demo $url is the varible it is stored under//
$read = file_get_contents($url);
//this gets the website, the website should now be stored as a varible called $read//
$write = file_put_contents("read.txt", $read);
//This should create a file called "read.txt" in same dir as file with all data from website (Helps For Editing)//
$bit = '<td class="cl_channel">';
//This is the part of site i have picked for selection of room names located in website.//
$count = 1;
$num = 0;
$data = explode($bit, $read);
//Explode creates an array of your choice of breaking point from data. (PHP starts with 0 for matches)//
while ($count < count($data))
{
$match = $data[$count];
//$match is now part whatever number $count is currently of the array of $data//
$match = explode(">", $match)[1];
//this is to remove the url from room name, the [1] on end means text after first ">"//
$match = explode("</a", $match)[0];
//$match should now be the rooms name, the [0] on end means we want text before</a//
if (strlen($match) > 1) goto dis;
goto next;
dis:
$num = $num + 1;
echo '['.$num.'] '.$match.'<br>';
//This should echo room names to your page or terminal the output shown is for webpage//
next:
$count = $count + 1;
}
//You should now have a complete list of chatrooms from webpage specifed//
echo 'List Completed Of "'.$num.'" Chatrooms';
?>


    View Demo Of This Code


Creating A Robot With PHP Sockets.
Below Code Should Connect A Bot To SPCN.io Chat As A Guest And Join Room "%#ds.test.room" Then Close.

<?PHP
ob_implicit_flush(true);
$host = "spcnip.d-web.site";
//Server Hostname//
$ip = gethostbyname("$host");
//Get servers IP From Hostname//
$port = "7778";
$chan = "%#ds.test.room";
$botsnick = ">Testbot_" . rand(1111,999999999);
//Random Nickname For Bot//
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
//Create a socket for connecting with.//
$open = socket_connect($socket, $ip, $port);
//Connect socket to specified ip & port//
$data = array();
$data[count($data)] = "NICK " . $botsnick;
$data[count($data)] = "USER :d-test";
$data = implode("\r\n", $data) . "\r\n";
//Created data to send to server as an array then turned into string ("\r\n" is new line return all data sent to server requires it)//
socket_write($socket, $data, strlen($data));
sleep(1);
$data = "CREATE " . $chan . "\r\n";
socket_write($socket, $data, strlen($data));
sleep(1);
while ($in = socket_read($socket, "81920"))
{
echo str_replace("\r\n", "<br>", $in) . "<br>";
ob_end_flush();
if (count(explode("JOIN", $in)) > 1)
{
$mode = "MODE " . $chan . " +pu\r\n";
socket_write($socket, $mode, strlen($mode));
sleep(2);
goto end;
}
}
end:
socket_close($socket);
echo "Script Completed";
?>


    View Demo Of This Code


PHP Function & Getting Data Specified In Link Into Script.
Below Code Is PHP Function To Reverse Text & Retrieving Data From URL

<?PHP
if (!isset($_GET['data1'])) $data = "Whatever";
else $data1 = $_GET['data1'];
if (!isset($_GET['data2'])) $data = "Something";
else $data2 = $_GET['data2'];
//Get data from url into var the url should be http://yoursite.com/file.php?data1=whatever&data2=something//
echo "Reversing Test From Input<br>";
echo $data1 . " = " . reverseTEXT($data1) . "<br>";
echo $data2 . " = " . reverseTEXT($data2) . "<br>";
function reverseTEXT($data) {
$len = strlen($data);
while ($len > 0)
{
$len = $len - 1;
$out .= substr($data,$len,1);
}
return $out;
}
?>


    View Demo Of This Code