[PHP] Hello everybody - php newbie from switzerland
Hello everybody, I am NIck, from Locarno (southern switzerland) i am getting into php development for my own start-up company, maybe there are other people near me that would be nice to know for networking and alike. I will post here all my questions if i don't find any answer already on this list. Cheers from Switzerland Nick -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] replying to list
Not really i think, because by replying it just direct reply to the OP, while other systems like google groups for example by replying you just post to the list, and actually make more sense. the easy way is to hit reply and change the "to" into php-general@lists.php.net or reply to all and replace "to" with the "cc". I think the best practice is to take this 5 second to take care of this in order to avoid duplicate message to others. cheers Nick On Apr 21, 2010, at 12:45 PM, Karl DeSaulniers wrote: > Exactly. > :) > > Karl > > On Apr 21, 2010, at 5:38 AM, David McGlone wrote: > >> Maybe it's not how the list is set up, but instead how people are >> replying to the list. > > Karl DeSaulniers > Design Drumm > http://designdrumm.com > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] escape \n
Hello guys i am trying to figure out what is worng with thoose special escaped character, like \n \t \r ... As i cannot make them working. The browser doesn't display them, but doesn't eithr crate a new line, or else. I am using them fro example like this: print: "this shoudl be on a line \nwhile this on a new line"; I've searched google and saw man people struggling with this, but apparently not a clear answer to whymaybe is a stupid beginner question, but i would just like to know. (Personally i solved for the moment by printing out or , but i would like to understand this. Cheers, Nick
Re: [PHP] escape \n
Thanks everybody! On Apr 23, 2010, at 10:05 AM, Ashley Sheridan wrote: > On Fri, 2010-04-23 at 09:51 +0200, Nick Balestra wrote: >> >> Hello guys i am trying to figure out what is worng with thoose special >> escaped character, like \n \t \r ... >> >> As i cannot make them working. The browser doesn't display them, but doesn't >> eithr crate a new line, or else. >> I am using them fro example like this: >> >> print: "this shoudl be on a line \nwhile this on a new line"; >> >> I've searched google and saw man people struggling with this, but apparently >> not a clear answer to whymaybe is a stupid beginner question, but i >> would just like to know. (Personally i solved for the moment by printing >> out or , but i would like to understand this. >> >> Cheers, Nick > > By default, PHP sends out HTML headers. Browsers ignore extraneous > white-space characters, and also new lines, carriage returns and tabs, > converting them all to a single space character. > > If you view the source in your browser, you'll see the newlines, but in > regular display, your text is treated as HTML. > > There is a function in PHP called nl2br, which accepts a string and returns > the same one with all the newlines replaced with automatically, which > might be easier to use if your content is in a string. Otherwise, the only > way to get new lines on your actual page is to either manually use tags, > put the text inside a block, or use CSS to preserve the white-space. > > Thanks, > Ash > http://www.ashleysheridan.co.uk > >
[PHP] multi dimensional array question
hello everybody here is my array(s) $us_census = array('NY' => array('New York' => 8008278), 'CA' => array('Los Angeles' => 3694820, 'San Diego' => 1223400), 'IL' => array('Chicago' => 2896016), 'TX' => array('Houston' => 1953631, 'Dallas' => 1188580, 'San Antonio' => 1144646), 'PA' => array('Philadelphia' => 1517550), 'AZ' => array('Phoenix' => 1321045), 'MI' => array('Detroit' => 951270)); print "StateCityPopulationTotal"; // $state is the key and $states is the value foreach ($us_census as $state => $cities) { // $state is the key and $habitant is the value foreach ($cities as $city => $habitants){ print "$state$city$habitants"; } } Now i also want to be able to count the total population per state, i am stucked... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] multi dimensional array question
thanks Piero! i was trying to solve an excercise on "learning php5" (O'reilyl) book. I am happy abotut his solution with the array_sum funtion you suggested, and my multidimensional array make much more sense to mee then they suggested solution that also much more line of code comapred... look: my solution (with Piero suggeston): and ont he bottom the book solution. what do u say is the best one? why? i am learning so i am interested in understanding why a solution can be better then an other... $us_census = array('NY' => array('New York' => 8008278), 'CA' => array('Los Angeles' => 3694820, 'San Diego' => 1223400), 'IL' => array('Chicago' => 2896016), 'TX' => array('Houston' => 1953631, 'Dallas' => 1188580, 'San Antonio' => 1144646), 'PA' => array('Philadelphia' => 1517550), 'AZ' => array('Phoenix' => 1321045), 'MI' => array('Detroit' => 951270)); print "StateCityPopulationTotal"; foreach ($us_census as $state => $cities) { foreach ($cities as $city => $habitants){ $tothabitants += $habitants; print "$state$city$habitants"; } } print "$tothabitants"; foreach ($us_census as $state => $cities) { $population_per_state = array_sum($cities); print "$state $population_per_state"; } -- the book solution: $population = array('New York' => array('state' => 'NY', 'pop' => 8008278), 'Los Angeles' => array('state' => 'CA', 'pop' => 3694820), 'Chicago' => array('state' => 'IL', 'pop' => 2896016), 'Houston' => array('state' => 'TX', 'pop' => 1953631), 'Philadelphia' => array('state' => 'PA', 'pop' => 1517550), 'Phoenix' => array('state' => 'AZ', 'pop' => 1321045), 'San Diego' => array('state' => 'CA', 'pop' => 1223400), 'Dallas' => array('state' => 'TX', 'pop' => 1188580), 'San Antonio' => array('state' => 'TX', 'pop' => 1144646), 'Detroit' => array('state' => 'MI', 'pop' => 951270)); $state_totals = array( ); $total_population = 0; print "CityPopulation\n"; foreach ($population as $city => $info) { $total_population += $info['pop']; $state_totals[$info['state']] += $info['pop']; print "$city, {$info['state']}{$info['pop']}\n"; } foreach ($state_totals as $state => $pop) { print "$state$pop\n"; } print "Total$total_population\n"; print "\n";
Re: [PHP] multi dimensional array question
Thanks! I'll agree with you abotu ur points, i just started php few days ago..so i am in the first phase of learnign it...and this list is so gr8! thanks evrybody cheers, Nick On May 1, 2010, at 6:11 PM, Programming Guides wrote: > On Fri, Apr 30, 2010 at 7:33 PM, Nick Balestra wrote: > thanks Piero! > > i was trying to solve an excercise on "learning php5" (O'reilyl) book. > > I am happy abotut his solution with the array_sum funtion you suggested, and > my multidimensional array make much more sense to mee then they suggested > solution that also much more line of code comapred... > > look: my solution (with Piero suggeston): and ont he bottom the book > solution. what do u say is the best one? why? i am learning so i am > interested in understanding why a solution can be better then an other... > > $us_census = array('NY' => array('New York' => 8008278), > 'CA' => array('Los Angeles' => 3694820, > 'San Diego' > => 1223400), > 'IL' => array('Chicago' => 2896016), > 'TX' => array('Houston' => 1953631, > 'Dallas' => > 1188580, > 'San Antonio' > => 1144646), > 'PA' => array('Philadelphia' => 1517550), > 'AZ' => array('Phoenix' => 1321045), > 'MI' => array('Detroit' => 951270)); > > > > print > "StateCityPopulationTotal"; > > > foreach ($us_census as $state => $cities) { > >foreach ($cities as $city => $habitants){ > >$tothabitants += $habitants; > >print > "$state$city$habitants"; >} >} > > print "$tothabitants"; > > > foreach ($us_census as $state => $cities) { >$population_per_state = array_sum($cities); >print "$state $population_per_state"; > } > > -- > the book solution: > > > $population = array('New York' => array('state' => 'NY', 'pop' => 8008278), > 'Los Angeles' => array('state' => 'CA', 'pop' => 3694820), > 'Chicago' => array('state' => 'IL', 'pop' => 2896016), > 'Houston' => array('state' => 'TX', 'pop' => 1953631), > 'Philadelphia' => array('state' => 'PA', 'pop' => 1517550), > 'Phoenix' => array('state' => 'AZ', 'pop' => 1321045), > 'San Diego' => array('state' => 'CA', 'pop' => 1223400), > 'Dallas' => array('state' => 'TX', 'pop' => 1188580), > 'San Antonio' => array('state' => 'TX', 'pop' => 1144646), > 'Detroit' => array('state' => 'MI', 'pop' => 951270)); > > $state_totals = array( ); > $total_population = 0; > print "CityPopulation\n"; > foreach ($population as $city => $info) { > > > $total_population += $info['pop']; > > $state_totals[$info['state']] += $info['pop']; > print "$city, {$info['state']}{$info['pop']}\n"; > } > > foreach ($state_totals as $state => $pop) { > print "$state$pop\n"; > } > print "Total$total_population\n"; > print "\n"; > > > > > > I actually prefer your solution - it's easier to read and understand. On the > other hand the solution the book offers has the advantage of being more > extensible in that more pieces of information can be added per city. > > One thing I dont like about both solutions is that they both intertwine > computation logic with presentation. A *much* better approach in this case is > to first calculate all population data you need and put together one data > structure that has all of that. Only after you have that ready do you begin > to output HTML. And while outputting HTML the only PHP you should need is to > iterate over your data structure and output. > > -- > http://programming-guides.com
[PHP] Joomla FrameWork ::
I am trying to understand how the joomla framework works, i see an heavy usage of " :: " in its code, here an example: function edit () { JRequest::setVar('view, 'single'); $this ->display(); } from my really basic php understanding in the function edit i call a function setVar() and i pass the paramter 'view' and 'single' in it then the output ($this) is passed to the display() function. My question is what does :: means? an more precisely referring to the example: JRequest::setVar('view, 'single'); how do you read it and how do you manage it? Cheers, Nick -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Joomla FrameWork ::
I think si related to class and methods, JRequest Class have a method called setVar, right? if this is correct sorry for posting the question, i just haven't started yet classes and methods...;-) On May 2, 2010, at 4:41 PM, Nick Balestra wrote: > I am trying to understand how the joomla framework works, i see an heavy > usage of " :: " in its code, here an example: > > function edit () > { > JRequest::setVar('view, 'single'); > $this ->display(); > } > > > from my really basic php understanding in the function edit i call a function > setVar() and i pass the paramter 'view' and 'single' in it then the output > ($this) is passed to the display() function. > > My question is what does :: means? an more precisely referring to the > example: JRequest::setVar('view, 'single'); how do you read it and how do > you manage it? > > Cheers, Nick -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Joomla FrameWork ::
Thank a lot for pointing me to this, as you wrote u are right, haven't started yet with oo so of course i wasn't able to understand what was this all about. thanks again Nick On May 2, 2010, at 4:52 PM, viraj wrote: > hi nick, > :: is what we call 'scope resolution operator', $this is your 'current scope'. > > i guess you better read > http://www.php.net/manual/en/language.oop5.php.. all sections :)) > > > ~viraj > > > > On Sun, May 2, 2010 at 8:11 PM, Nick Balestra wrote: >> I am trying to understand how the joomla framework works, i see an heavy >> usage of " :: " in its code, here an example: >> >> function edit () >>{ >>JRequest::setVar('view, 'single'); >>$this ->display(); >>} >> >> >> from my really basic php understanding in the function edit i call a >> function setVar() and i pass the paramter 'view' and 'single' in it then the >> output ($this) is passed to the display() function. >> >> My question is what does :: means? an more precisely referring to the >> example: JRequest::setVar('view, 'single'); how do you read it and how do >> you manage it? >> >> Cheers, Nick >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php