PHP - Arenas Here To Learn
Hello everyone, my name is Joe. I have no clue how to code in PHP. But have some decent knowdlege when it comes to HTML and CSS. But there are some PHP scripts i would like to build and i am very hopefull with the help of the community i will be able to learn PHP and get help with my long over due PHP projects.
Thank you for reading!
Similar TutorialsShould one learn object oriented programming first, before getting to learn a framework?
I have been interested in CakePHP.
Hello everyone - I have picked dup a book on php and SQL and have been quaking through it. I have come across a problem with a foreach statement that I can not resolve. Any help and advice is greatly appreciated!
<?php try { $pdo = new PDO('mysql:host=localhost;dbname=ijdb; charset=utf8', 'ijdbuser', 'mypassword'); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = 'SELECT `joketext` FROM `joke`'; $result = $pdo->query($sql); while ($row = $result->fetch()) { $jokes[] = $row['joketext']; } } catch (PDOException $e) { $output = 'Unable to connect to the database server: ' . $e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine(); } include __DIR__ . '/../templates/jokes.html.php'; and the other file
<!doctype html> <html> <head> <meta charset="utf-8"> <title>List of jokes</title> </head> <body> <?php if (isset($error)): ?> <p> <?php echo $error; ?> </p> <?php else: ?> <?php foreach($jokes as $joke ): ?> <blockquote> <p> <?php echo htmlspecialchars($joke, ENT_QUOTES, 'UTF-8') ?> </p> </blockquote> <?php endforeach; ?> <?php endif; ?> </body> </html>
Ok figured I'd go out and try to write me something for my site that I want and can't seem to be able to find what I want...sooooooooooo
I'm trying to create an NFL score 'ticker' and so far I've gotten as far as fetching the xml.. that part works LOL
I have been sitting here for a few hours trying to figure out how to do a foreach statement that works... I've hit a brick wall because I just can't seem to figure it out...
I have even tried a few I've found in other places but no go...
Here is what I have so far:
<?php $url="http://www.nfl.com/liveupdate/scorestrip/postseason/ss.xml"; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); // get the url contents $data = curl_exec($ch); // execute curl request curl_close($ch); $xml = simplexml_load_string($data); print_r($xml); //just keeping this here so I can see it for now ?>I know that part is working as you can see I left the print_r in it temp so I can still see I"m getting what I need... Again the problem is I'm not getting a functional foreach that I can get to work.. I either get nothing back or an error of some kind and trust me I've tried as many as I could find LOL SimpleXMLElement Object ( [gms] => SimpleXMLElement Object ( [@attributes] => Array ( [w] => 18 [y] => 2014 [t] => POST [gd] => 0 [bf] => 0 [bph] => 0 ) [g] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [eid] => 2015010301 [gsis] => 56492 [d] => Sat [t] => 8:15 [q] => P [htn] => Pittsburgh Steelers [hnn] => steelers [h] => PIT [hs] => 0 [vtn] => Baltimore Ravens [vnn] => ravens [v] => BAL [vs] => 0 [n] => NBC [rz] => 0 [ga] => [o] => 1 [gt] => WC ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [eid] => 2015010400 [gsis] => 56493 [d] => Sun [t] => 1:05 [q] => P [htn] => Indianapolis Colts [hnn] => colts [h] => IND [hs] => 0 [vtn] => Cincinnati Bengals [vnn] => bengals [v] => CIN [vs] => 0 [n] => CBS [rz] => 0 [ga] => [o] => 2 [gt] => WC ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [eid] => 2015011000 [gsis] => 0 [d] => Jan 10 [t] => 4:35 [q] => P [htn] => New England Patriots [hnn] => patriots [h] => NE [hs] => 0 [vnn] => [v] => TBD [vs] => 0 [n] => NBC [rz] => 0 [ga] => [o] => 3 [gt] => DIV ) ) [3] => SimpleXMLElement Object ( [@attributes] => Array ( [eid] => 2015011101 [gsis] => 0 [d] => Jan 11 [t] => 4:40 [q] => P [htn] => Denver Broncos [hnn] => broncos [h] => DEN [hs] => 0 [vnn] => [v] => TBD [vs] => 0 [n] => CBS [rz] => 0 [ga] => [o] => 4 [gt] => DIV ) ) [4] => SimpleXMLElement Object ( [@attributes] => Array ( [eid] => 2015011801 [gsis] => 0 [d] => Jan 18 [t] => 6:40 [q] => P [hnn] => [h] => TBD [hs] => 0 [vnn] => [v] => TBD [vs] => 0 [n] => CBS [rz] => 0 [ga] => [o] => 5 [gt] => CON ) ) [5] => SimpleXMLElement Object ( [@attributes] => Array ( [eid] => 2015011800 [gsis] => 0 [d] => Jan 18 [t] => 3:05 [q] => P [hnn] => [h] => TBD [hs] => 0 [vnn] => [v] => TBD [vs] => 0 [n] => FOX [rz] => 0 [ga] => [o] => 6 [gt] => CON ) ) [6] => SimpleXMLElement Object ( [@attributes] => Array ( [eid] => 2015011100 [gsis] => 0 [d] => Jan 11 [t] => 1:05 [q] => P [htn] => Green Bay Packers [hnn] => packers [h] => GB [hs] => 0 [vnn] => [v] => TBD [vs] => 0 [n] => FOX [rz] => 0 [ga] => [o] => 7 [gt] => DIV ) ) [7] => SimpleXMLElement Object ( [@attributes] => Array ( [eid] => 2015011001 [gsis] => 0 [d] => Jan 10 [t] => 8:15 [q] => P [htn] => Seattle Seahawks [hnn] => seahawks [h] => SEA [hs] => 0 [vnn] => [v] => TBD [vs] => 0 [n] => FOX [rz] => 0 [ga] => [o] => 8 [gt] => DIV ) ) [8] => SimpleXMLElement Object ( [@attributes] => Array ( [eid] => 2015010401 [gsis] => 56494 [d] => Sun [t] => 4:40 [q] => P [htn] => Dallas Cowboys [hnn] => cowboys [h] => DAL [hs] => 0 [vtn] => Detroit Lions [vnn] => lions [v] => DET [vs] => 0 [n] => FOX [rz] => 0 [ga] => [o] => 9 [gt] => WC ) ) [9] => SimpleXMLElement Object ( [@attributes] => Array ( [eid] => 2015010300 [gsis] => 56491 [d] => Sat [t] => 4:35 [q] => P [htn] => Carolina Panthers [hnn] => panthers [h] => CAR [hs] => 0 [vtn] => Arizona Cardinals [vnn] => cardinals [v] => ARI [vs] => 0 [n] => ESPN [rz] => 0 [ga] => [o] => 10 [gt] => WC ) ) [10] => SimpleXMLElement Object ( [@attributes] => Array ( [eid] => 2015012500 [gsis] => 0 [d] => Jan 25 [t] => 8:00 [q] => P [htn] => Team Cris Carter [hnn] => team carter [h] => CRT [hs] => 0 [vtn] => Team Michael Irvin [vnn] => team irvin [v] => IRV [vs] => 0 [n] => ESPN [rz] => 0 [ga] => [o] => 11 [gt] => PRO ) ) [11] => SimpleXMLElement Object ( [@attributes] => Array ( [eid] => 2015020100 [gsis] => 0 [d] => Feb 1 [t] => 6:30 [q] => P [hnn] => [h] => TBD [hs] => 0 [vnn] => [v] => TBD [vs] => 0 [n] => NBC [rz] => 0 [ga] => [o] => 12 [gt] => SB ) ) ) ) [gds] => SimpleXMLElement Object ( ) )My object is returning this and that's great... but my foreach skills need a TON of work apparently... I think I've looked at it too much and too long... some suggestions would be VERY much appreciated... Probably a bit big of a project to try on my first real attempt but I just went through the foreach in my tutorial but it's just not working.... What I'm looking to do is output the d, t, htn, vtn, hs, vs... I was trying to just get it to show just one of those but no go... Thanks everyone!! Hello, I'm a newbie and would like to learn PHP. I have some HTML and CSS skills, but would very much like to upgrade them to PHP. How can I do that? What materials do you suggest I read?... Thanks,
This script with minor changes came from a tutorial. I did a var dump and get a NULL result. Can anyone tell me why? <?php /** Get web page via HTTP GET using Libcurl. */ function getPageDetails($target, $referer) { $info = curl_init(); //settings curl_setopt($info, CURLOPT_HEADER, true); curl_setopt($info, CURLOPT_COOKIEJAR, "cookie_jar.txt"); curl_setopt($info, CURLOPT_COOKIEFILE, "cookies.txt"); curl_setopt($info, CURLOPT_USERAGENT, "imagimediabot2"); curl_setopt($info, CURLOPT_URL, $url); curl_setopt($info, CURLOPT_REFERER, $referer); curl_setopt($info, CURLOPT_FOLLOWLOCATION, true); curl_setopt($info, CURLOPT_MAXREDIRS, 4); curl_setopt($info, CURLOPT_RETURNTRANSFER, true); //request $output = curl_exec($info); curl_close ($info); //seperate head and body $separator = "\r\n\r\n"; $header = substr( $output, 0, strpos( $output, $separator ) ); $body_start = strlen( $header ) + strlen( $separator ); $body = substr($output, $body_start, strlen($output)-$body_start); // parse headers $header_array = Array(); foreach (explode ("\r\n", $header) as $i => $line) { if($i === 0) { $header_array['http_code'] = $line; $status_info = explode( " ", $line ); $header_array['status_info'] = $status_info; } else { list ( $key, $value ) = explode ( ': ', $line ); $header_array[$key] = $value; } } $ret = Array("headers"=>$header_array,"body"=>$body); return $ret; } $page = getPageDetails("https://imagimedia.co.za", ""); $headers = $page['headers']; $http_status_code = $headers['http_code']; $body = $page['body']; var_dump($header_array) ?>
I am trying to find a tutorial on how to perform a depth first search. I've seen pseudocodes and sources in other languages, but I just can't implement it in PHP no matter what I try. Can anyone show me how or where I can read up on it or how to do it? Hello Guys... I'm new to php & mySQL... I need help... Need something to know... please help me... I'm using ubuntu 11.10, Aptana Studio 3, xampp 1.7.7. Also i'm using windows 7, notepad++ & wamp. When I visit "localhost" on my firefox. I saw a xampp or wamp welcome page. The name of the file is "index.php". 1. I need to know can I delete this file ? Bcoz i'm working on another file but it's the same file name. 2. When I upload my site on host like hostgator. How do i edit my live site? And preview it. 3. How do i store my post on database ? Like fb status update, blogger post or forum post I wanna write a site that i can post something without using html <p></p>. The main problem when i need to post something then everytime I need to edit the source code. Example:<p>some text here</p>. I don't wanna edit source everytime. Another Ques: Is Aptana Studio and notepad++ enough to write a site or I need another tool ? Any book suggestion ? please guys help me i'm new to php & mySQL.. Hi all, I am an intermediate PHP Programmer, but I'm now stuck with getting any further. I am currently developing a CMS with a few people. However, I wish to put that aside for a month or so and learn PHP a bit better. Can anyone suggest a fairly "easy" project for me to do to learn a bit more about PHP? Best Regards, DM So I am fairly new to PHP. I have dabbling experience in a slew of languages, C++, Python, Java, Perl, Javascript, Haskell and I am fluent in HTML but not so great with CSS. I am currently working on developing a browser game using PHP and am going to be asking for help making it work. When I ask stupid questions, as I am sure I will, I hope people will help me learn to ask better ones.
So I started learning how to code php with usercake. I then went to use different things like fileNice for directory listing and I went to make a music lister with music player running mainly (EDM) .mp3's.
I have uploaded a copy of my music.php file and I would love some help on how to develop my site further!
https://github.com/3...aster/music.php
This is the part I need help developing:
<?php function getUploadedFiles($directory){ $folder = opendir($directory); while ($file = readdir($folder)) { if($file !== '.' && $file !== '..') { $filename = $directory.''.$file; $file_array[] = array('filename' => $file); } } return $file_array; } $music = getUploadedFiles('../Music/EDM'); foreach($music as $value) { echo '<div class="well well-sm">'; echo '<li class="list-group-item list-group-item-success"><div class="alert alert-success" role="alert"><a href="../Music/EDM/'.$value['filename'].'"title="Play .$value" class="sm2_button"></a> '.$value['filename'].'</div></li>'; echo '<p><a href="../Music/EDM/'.$value['filename'].'"><button type="button" class="btn btn-sm btn-primary"><span class="glyphicon glyphicon-headphones"> </span> Listen</button></a> '; echo '<a href="../Music/EDM/'.$value['filename'].'" download><button type="button" class="btn btn-sm btn-success"><span class="glyphicon glyphicon-cloud-download"></span> Download</button></p></br></a></p>'; echo '<p><a class="btn btn-default" href="#" role="button">View details »</a></p>'; echo '</div>'; } ?>I would love to figure out how to use "echo '<p><a class="btn btn-default" href="#" role="button">View details »</a></p>';" to show time of when song was added, so Time last modified ? Hopefully I can learn how to set individual counters instead of them being the same for all the songs :/ Here is a link to the site with everything running: http://thebatcave.x10.mx/dev/music.php Tell me what you think ? Edited by 321System123, 10 August 2014 - 08:45 PM. I am looking for a blog app or also a magazine type web app for CakePHP to learn from - any suggestions?
This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=321790.0 Hello guys, I'm trying to learn and understand the process of connecting a client to TCP connection! Now I'm trying to build a mobile chat application which I want it to connect to my server (hosted in media temple) which I hate about media temple is the way they name the variable we used to know like "localhost" to some random strange string! anyway that's not the topic. But you got the idea it's a chat app as the client on a mobile device! that will try to connect to my server. Now I have tried sooo many scripts, tutorials ... etc. But I didn't get it. I need to know the process or even get it to work so I'll be able to know what's going on from the code. Here's what I have (as of now) on the mobile (client side): // create the socekt object var socket = Titanium.Network.createTCPSocket({ hostName:"mywebsite.com", port:4446, // some port I just typed because I don't know what port! mode:Titanium.Network.READ_WRITE_MODE }); // connect button connectBtn.addEventListener('click', function() { if(socket.isValid == false){ try { socket.connect(); socket.listen(); messageLabel.text = 'Opened!'; } catch (e) { messageLabel.text = 'Exception: '+e; } } }); // reader listener socket.addEventListener('read', function(e) { Ti.API.info(JSON.stringify(e)); Ti.API.info(e['from'] + ':' + e['data'].text); }); //writer button writeButton.addEventListener('click', function() { try { socket.write("writing...this"); } catch (e) { alert(e); } }); //## //## Credits goes to people in: http://www.functionblog.com/?p=67=1#viewSource //## <?php // PHP SOCKET SERVER error_reporting(E_ERROR); // Configuration variables $host = "127.0.0.1"; $port = 4041; $max = 20; $client = array(); // No timeouts, flush content immediatly set_time_limit(0); ob_implicit_flush(); // Server functions function rLog($msg){ $msg = "[".date('Y-m-d H:i:s')."] ".$msg; print($msg."\n"); } // Create socket $sock = socket_create(AF_INET,SOCK_STREAM,0) or die("[".date('Y-m-d H:i:s')."] Could not create socket\n"); // Bind to socket socket_bind($sock,$host,$port) or die("[".date('Y-m-d H:i:s')."] Could not bind to socket\n"); // Start listening socket_listen($sock) or die("[".date('Y-m-d H:i:s')."] Could not set up socket listener\n"); rLog("Server started at ".$host.":".$port); // Server loop while(true){ socket_set_block($sock); // Setup clients listen socket for reading $read[0] = $sock; for($i = 0;$i<$max;$i++){ if($client[$i]['sock'] != null) $read[$i+1] = $client[$i]['sock']; } // Set up a blocking call to socket_select() $ready = socket_select($read,$write = NULL, $except = NULL, $tv_sec = NULL); // If a new connection is being made add it to the clients array if(in_array($sock,$read)){ for($i = 0;$i<$max;$i++){ if($client[$i]['sock']==null){ if(($client[$i]['sock'] = socket_accept($sock))<0){ rLog("socket_accept() failed: ".socket_strerror($client[$i]['sock'])); }else{ rLog("Client #".$i." connected"); } break; }elseif($i == $max - 1){ rLog("Too many clients"); } } if(--$ready <= 0) continue; } for($i=0;$i<$max;$i++){ if(in_array($client[$i]['sock'],$read)){ $input = socket_read($client[$i]['sock'],1024); if($input==null){ unset($client[$i]); } $n = trim($input); $com = split(" ",$n); if($n=="EXIT"){ if($client[$i]['sock']!=null){ // Disconnect requested socket_close($client[$i]['sock']); unset($client[$i]['sock']); rLog("Disconnected(2) client #".$i); for($p=0;$p<count($client);$p++){ socket_write($client[$p]['sock'],"DISC ".$i.chr(0)); } if($i == $adm){ $adm = -1; } } }elseif($n=="TERM"){ // Server termination requested socket_close($sock); rLog("Terminated server (requested by client #".$i.")"); exit(); }elseif($input){ // Strip whitespaces and write back to user // Respond to commands /*$output = ereg_replace("[ \t\n\r]","",$input).chr(0); socket_write($client[$i]['sock'],$output);*/ if($n=="PING"){ socket_write($client[$i]['sock'],"PONG".chr(0)); } if($n=="<policy-file-request/>"){ rLog("Client #".$i." requested a policy file..."); $cdmp="<?xml version=\"1.0\" encoding=\"UTF-8\"?><cross-domain-policy xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://www.adobe.com/xml/schemas/PolicyFileSocket.xsd\"><allow-access-from domain=\"*\" to-ports=\"*\" secure=\"false\" /><site-control permitted-cross-domain-policies=\"master-only\" /></cross-domain-policy>"; socket_write($client[$i]['sock'],$cdmp.chr(0)); socket_close($client[$i]['sock']); unset($client[$i]); $cdmp=""; } } }else{ //if($client[$i]['sock']!=null){ // Close the socket //socket_close($client[$i]['sock']); //unset($client[$i]); //rLog("Disconnected(1) client #".$i); //} } } } // Close the master sockets socket_close($sock); ?> I just want to understand how am I gonna implement this! I need to know how does it work! You help is much appreciated! This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=330649.0 I have spent the last few days going over Zend framework 2, and I am finding it extremely complex. Not saying it shouldn't be, but it seems to solve problems I never have come across (so to speak) .
For instance:
Routing is super complex. I usually use torophp - which is simple & gets the job done.
Dependency injection - example of problem I have never come across.
My motivations for learning zend, are -
1. To write modular reuseable code.
2. Learn advanced / modern PHP , as far as frameworks are concerned I just know codeigniter.
3. A framework with good long term support.
Is there some other framework that is easier to learn ? and that would satisfy my requirements ?
I have been programming in PHP for the last 2-3 years btw, so I know my way around
Thanks
Edited by nik_jain, 31 August 2014 - 09:56 AM. i keep seeing people use this kind of code but i cant find any document or help web pages on it. im sure there is but i done know what to call it. i would really like to learn more about it for example Code: [Select] $lang = isset($_GET['lang']) ? (int)$_GET['lang'] : 1; or Code: [Select] return !empty($result_array) ? array_shift($result_array) : false; This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=326872.0 Hello,
Can you guys point me to something where I can follow some tutorial or something and learning CI?
I've already made tons of 'Cars' models... 'Dogs' .. 'Cats'.. etc but I really need some project where I can follow steps to creat and learn while I create.
p.s. I think I post this thread in right place but please correct me if is wrong.
Thank's!
Where would you guys recommend I go to learn and become familiar with writing Object Oriented PHP code? Also what are the advantages of writing object oriented code? Is it better than the 'traditional' coding style? I mean without using Objects, Classes, Methods, etc.. Is one way more efficient than the other? I've been seeing a lot of object oriented php code lately, and I'm just curious and want to learn the concept of OOP, any help is appreciated. Thanks! -CLUEL3SS This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=314342.0 |