PHP - [starting To Learn Php And Html] Need Help Using Php!
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. Similar TutorialsHello dear friends, first of all : merry merry Xmas!!! i want to parse with the simple Simple HTML DOM Parser, well i am pretty new to php and to the Simple HTML DOM Parser. My example: http://schulen.bildung-rp.de/gehezu/startseite/einzelanzeige.html?tx_wfqbe_pi1[uid]=60119 I want to collect the data in the block: I have investigated the sourcecode - and found out that the attribute of interest should be this one: class="content"div class="content"><!-- TYPO3SEARCH_begin --> here the code is: - my trails. // inculde the Simple HTML DOM Parser include_once('simple_html_dom.php'); // get the file we want to parse right now,create a DOM $html = file_get_html(''); // simple_html_dom::find() creates a new // simple_html_dom-Objekt, that consists out of // corresponding childelements foreach($html->find('class: content ') as $h3) { // simple_html_dom::get the text in a tag // den Text innerhalb eines Tags if($h3->innertext == 'Text of a H3 Tag') { break; } } // simple_html_dom::next_sibling() gives the // next Element $table = $h3->next_sibling(); but believe me - it gives me not back what is aimed. what have id done wrong...? dbone Should one learn object oriented programming first, before getting to learn a framework?
I have been interested in CakePHP.
started learning php yesterday at w3schools was looking for a great forum to ask questions as i go along. bumped into phpfreaks. looking forward to mastering the art
But I need help in an issue I have been having for awhile now. Some reason when I try to call for online status it does not work sometimes i can get it to show the default code 1 which means online. But I am trying to get it to say Online and Offline and so on. I do not get what I am doing wrong my website using mysql so not sure if its having trouble reading the database or what. here is the code...
<?php class steam { public $api = STEAM_API; public $returnUrl = URL; public $user = array(); function __construct() { $this->setUserInfo(); } function isLoggedin() { if(isset($_SESSION['steam'])) { return true; } return false; } function showLogoutButton() { echo "<br /><a href=\"logout.php\">Logout</a>"; //logout button } function steamlogin() { require_once(INCLUDES.'/openid.php'); try { // Change 'localhost' to your domain name. $openid = new LightOpenID($this->returnUrl); //dump($openid); if(!$openid->mode) { if(isset($_GET['login'])) { $openid->identity = 'http://steamcommunity.com/openid'; header('Location: ' . $openid->authUrl()); } echo "<a href=\"?login\"><img src=\"http://steamcommunity-a.akamaihd.net/public/images/signinthroughsteam/sits_small.png\"></a>"; } elseif($openid->mode == 'cancel') { echo 'User has canceled authentication!'; } else { if($openid->validate()) { $id = $openid->identity; $ptn = "/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/"; preg_match($ptn, $id, $matches); $_SESSION['loginid'] = $matches[1]; //die('Here'); header('Location: index.php'); exit; } else { echo "User is not logged in.\n"; } //die('here we are'); } } catch(ErrorException $e) { echo $e->getMessage(); } } function doLogout() { if(isset($_POST['steamid'])) { unset($_POST['steamid']); } header('Location: index.php'); exit; } function setUserInfo() { global $DB; if($this->isLoggedin()) { // Grab the info from the session $userData = $DB->getUserById($_SESSION['steam']); if(isset($userData['steamid'])) { $this->user = $userData; } else { unset($_SESSION['steam']); die('Could not get user'); } } elseif(isset($_SESSION['loginid'])) { $url = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key='.$this->api.'&steamids='.$_SESSION['loginid']; $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $url); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true); $content = curl_exec($ch); curl_close($ch); $content = json_decode($content, true); $_SESSION['steam'] = $_SESSION['loginid']; // Set the database values $values = array( 'steamid' => $content['response']['players'][0]['steamid'], 'communityvisibilitystate' => $content['response']['players'][0]['communityvisibilitystate'], 'profilestate' => $content['response']['players'][0]['profilestate'], 'personaname' => $content['response']['players'][0]['personaname'], 'lastlogoff' => isset($content['response']['players'][0]['lastlogoff']) ? $content['response']['players'][0]['lastlogoff'] : '', 'profileurl' => $content['response']['players'][0]['profileurl'], 'avatar' => $content['response']['players'][0]['avatar'], 'avatarmedium' => $content['response']['players'][0]['avatarmedium'], 'avatarfull' => $content['response']['players'][0]['avatarfull'], 'personastate' => $content['response']['players'][0]['personastate'], 'timecreated' => $content['response']['players'][0]['timecreated'], 'onlineoffline' => $this->user['personastate'] == 1 ? 'Online' : 'Offline', 'status' => $this->getOnlineStatus() ); if($values['lastlogoff'] == '') { $values['lastlogoff'] = 'NA'; } else { $values['lastlogoff'] = date("m/d/Y", $values['lastlogoff']); } // Are updating the user info or adding them? $userExists = $DB->getUserById($_SESSION['steam']); if(isset($userExists['steamid'])) { // We have this user, lets update their info $DB->update('users', $values, array('steamid' => $_SESSION['steam'])); } else { // New user, lets insert them $id = $DB->insert('users', $values); } unset($_SESSION['loginid']); $this->setUserInfo(); } } function getOnlineStatus($values) { switch($this->user['onlineoffline']) { case '0': default: $state = 'Offline'; break; case '1': $state = 'Online'; break; case '2': $state = 'Busy'; break; case '3': $state = 'Away'; break; case '4': $state = 'Snooze'; break; case '5': $state = 'Looking to trade'; break; case '6': $state = 'Looking to play'; break; } return $state; } ?>This is basically my entire code that calls the steam api. Here is the echo function I use to try and call it on a profile.php page... echo "<br /><strong>Online:</strong> " . $steam->user['onlineoffline'] . " ";So I would really appreciate it if someone can help me. I been trying to figure out this for the past week and its starting to drive me nuts and loose motivation on my project. Everything else works great minus this one issue. I have pretty much asked everywhere I can think of and no help. I use a function to call my database hint the global $DB; in my functions just to give you anymore information I can. $steam variable I believe is coming from my class at the very top of my code that is were $steam comes from. Thanks Edited by soslidesigns, 12 August 2014 - 01:50 PM. I am starting a project that will encompass the following- A forum script that will later be tied into it's own custom content management system. But I have some questions before I get too deep into starting: 1. What is the "most" secure way to code a forum system? 2. Shall I rely on 1 person to code or open it to the public to help too (open source)? 3. Which features of forum scripts do you like and why? 4. How should the plugin system (hooks) be designed? 5. Template system - what is the easiest way to make theming simple? These are just some of the basics that I am pondering at the moment. I know these may sound noobish but I would rather start this project the right way, instead of having it coded wrong etc.....and having to re-do everything down the road. I can't for the life of me understand how to perform this so I need some professional help here. I have a large array that contains some garbage every Nth and Nth + 1 element that needs to go away. array_filter doesn't work with keys but anyhow, i wouldn't know how to design the function. My keys are numeric, starting from 0. The keys I want to remove are part of this sequence: 8, 9, 18, 19, 28, 29 ... Can someone help me design a generic function to remove these keys? function filter_keys($array, $n, $offset) {} $new_array = filter_keys($array, 10, 8 ); I would maybe have to run this function twice, once for 8 offset and once for 9 offset. 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, 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!!
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) ?>
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>
I am wondering whether there is a way to do a foreach loop for an array, without starting at index[0]. Say, for example, I wanted to start displaying the contents of a 20 item array starting at index 5, what is the best way to do it? I know of this way, but it seems too crude (ie. there has to be a better way): $count = 0; foreach($array as $item) { if ($count > 5) {echo $item;} $count++; } Any other ideas?? Hey guys just thought I'd introduce myself as it's a polite thing to do.
My name is Nick I am currently a front end developer and love learning new technologies so it looks like PHP is my next step.
I hope to learn and give whatever knowledge I can back
Why do I get the following results (specifically the second example)? I thought it would be documented under https://www.php.net/manual/en/language.types.string.php, however, the word "ampersand" doesn't appear. Also, looked at logical operators, but found nothing. Thanks function test(string $string){ printf('%s %s %s 0'.PHP_EOL, gettype($string), $string, $string==0?'==':'!='); } test('123'); test('@123'); test('1@23'); test('123@');Quote
string 123 != 0
good day dear PHPFreaks - hello to everybody. i want to create a link parser. i have choosen to do it with Curl. I have some lines together now. Love to hear your review... Since i am new to programming i love to get some hints from experienced devs. Here some details: well since we have several hundred of resultpages derived from this one: http://www.educa.ch/dyn/79362.asp?action=search Note: i want to itterate over the resultpages - with a loop. http://www.educa.ch/dyn/79376.asp?id=1568 http://www.educa.ch/dyn/79376.asp?id=2149 i take this loop: for($i=1;$i<=$match[1];$i++) { $url = "http://www.example.com/page?page={$i}"; // access new sub-page, extract necessary data } what do you think? What about the Loop over the target-Urls? BTW: you see - there will be some pages empty. Note - the empty pages should be thrown away. I do not want to store "empty" stuff. well this is what i want to. And now i need to have a good parser-script. Note: this is a tree-part-job: 1. fetching the sub-pages 2. parsing them 3. storing the data in a mysql-db Well - the problem - some of the above mentioned pages are empty. so i need to find a solution to leave them aside - unless i do not want to populate my mysql-db with too much infos.. Btw- parsing should be a part that can be done with DomDocument - What do you think? I need to combine the first part with tthe second - can you give me some starting points and hints to get this. The fetching-job should be done with CuRL - and to process the data into a DomDocument-Parser-Job. No Problem he But how to do the DOM-Document-Job ... i have installed FireBug into the FireFox... now i have the Xpaths for the sites: http://www.educa.ch/dyn/79376.asp?id=1187 http://www.educa.ch/dyn/79376.asp?id=2939 http://www.educa.ch/dyn/79376.asp?id=1515 http://www.educa.ch/dyn/79376.asp?id=1469 Altes Schulhaus Ossingen :: /html/body/div[2] Guntibachstrasse 10 :: /html/body/div[4] 8475 Ossingen :: /html/body/div[6] sekretariat.psossingen@bluewin.ch :: /html/body/div[9]/a Tel:052 317 15 45 :: /html/body/div[11] Fax:052 317 04 42 :: /html/body/div[12] but how to appyl in the Simple DomDocument - i want to use this he http://simplehtmldom.sourceforge.net/ look forward to a hint that gives me a starting point This topic's house has been seized by the bank and it now lives in MySQL Help until it can get back on its feet. http://www.phpfreaks.com/forums/index.php?topic=358035.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=347327.0 Hello Community, good evening! i am having troubles with starting PHP on linux - [running OpenSuse-Linux] Could not open input file: - suse-linux:/usr/perl # php -v PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/extensions/readline.so' - libedit.so.0: cannot open shared object file: No such file or directory in Unknown on line 0 PHP 5.3.4-dev (cli) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies suse-linux:/usr/perl # well what is wrong here...? 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 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.. |