The Grinding Shed: Php - The Grinding Shed

Jump to content

  • (3 Pages)
  • +
  • 1
  • 2
  • 3
  • You cannot start a new topic
  • You cannot reply to this topic

Php Please Help People?

#16 User is offline   Alexander Icon

  • Group: Admin
  • Posts: 3,097
  • Joined: 13-June 02
  • Gender:Male
  • Location:Your girlfriend's thoughts
  • Your fuckin' daddy

Posted 11 February 2004 - 02:53 PM

Well, we're living in a wierd world, Unfy.
It's not the houses, it's the spaces between the houses.
akpcep.com - Everything | alexanderking.co - Me
0

#17 User is offline   Green Mamba Icon

  • Group: Members
  • Posts: 84
  • Joined: 10-February 04
  • Location:3rd World
  • Interests:The Symbiosis of Life & Death, Comics & Web Design

Posted 11 February 2004 - 07:56 PM

Dear Teachers

I was doing lesson no 5 today and came upon the following problem in this exercise...

<?php
print "<table border="1">\n"; /*why am I getting a parse error here?*/
for ( $y=1; $y<=12; $y++ )
{
print "<tr>\n";
for ( $x=1; $x<=12; $x++ )
{
print "\t<td>";
print ($x*$y);
print "</td>\n";
}
print "</tr>\n";
}
print "</table>";
?>

Thanks

PS: This example was copied straight from Learn PHP in 24 Hours.
0

#18 User is offline   hollow Icon

  • Group: Members
  • Posts: 1,772
  • Joined: 27-August 01
  • Location:Newcastle upon Tyne (UK)

Posted 11 February 2004 - 08:02 PM

print "<table border="1">\n";

needs to be

print "<table border=\"1\">\n";

because the " denote the beginning and end of what you print. The backslash tells php to ignore that meaning and just print them.

Alex, It's down to habit / 6 and 2 3's etc that i'd usually do this:

foreach ($_POST as $key=>$val)
{
$_POST[$key]=stripslashes($val);
}
0

#19 User is offline   Alexander Icon

  • Group: Admin
  • Posts: 3,097
  • Joined: 13-June 02
  • Gender:Male
  • Location:Your girlfriend's thoughts
  • Your fuckin' daddy

Posted 11 February 2004 - 11:13 PM

That's the beauty of PHP, there's about 5 different ways to do everything, and the CPU/bandwidth cost difference is usually so minimal as to be irrelevant.
It's not the houses, it's the spaces between the houses.
akpcep.com - Everything | alexanderking.co - Me
0

#20 Guest_Unforgiven_*

  • Group: Guests

Posted 12 February 2004 - 12:35 AM

Alexander, on Feb 11 2004, 06:59 PM, said:

That's the beauty of PHP, there's about 5 different ways to do everything, and the CPU/bandwidth cost difference is usually so minimal as to be irrelevant.

That's programming in general.
0

#21 User is offline   Green Mamba Icon

  • Group: Members
  • Posts: 84
  • Joined: 10-February 04
  • Location:3rd World
  • Interests:The Symbiosis of Life &amp; Death, Comics &amp; Web Design

Posted 12 February 2004 - 04:56 AM

So, it eventually comes down to personal preference.

Thanks for that Hollow. Tried it last night and it works now.

In line with the last two posts I also tried without any quotes (border=1) and with single quotes (border='1'), both of which also works fine. I guess you only have to use the \ when the code you're inserting demands the use of double quotes (or with java that sometimes uses double and single quotes in one string)
0

#22 User is offline   hollow Icon

  • Group: Members
  • Posts: 1,772
  • Joined: 27-August 01
  • Location:Newcastle upon Tyne (UK)

Posted 12 February 2004 - 10:22 AM

No problem, see the firstpage for how to do large chunks of output without having to backslash every doublequote.

Alex, here's a function to get rid of characters that will break XML. It's the one we use to allow our press office to publish xml and pdf and they use all kinds of messed up characters.

function cleanForXML($string)
{     $output='';
      for($i=0;$i<=strlen($string);$i++)
      {
      $a=$string{$i};
          if($a=='&')
          {      $output.="&amp;";
          }
          else if(ord($a)>127)
          {      if(ord($a)=='145' or ord($a)=='146') $output.="'";
                 else if(ord($a)=='147' or ord($a)=='148') $output.="\"";
                 else if(ord($a)=='150') $output.="-";
                 else $output.="&#".ord($a).";";
          }
          else
          {      $output.=$a;
          }
      }
return($output);
}

// FOR EXAMPLE:
echo(cleanForXML("ABC & †‡‡‰Šz{‹œ��~åÔ³“‘�-€"));


edit - slightly modified, reformatted and have taken the counter out which was from an old version what used a while loop rather than a for...

This post has been edited by hollow: 12 February 2004 - 10:37 AM

0

#23 User is offline   Alexander Icon

  • Group: Admin
  • Posts: 3,097
  • Joined: 13-June 02
  • Gender:Male
  • Location:Your girlfriend's thoughts
  • Your fuckin' daddy

Posted 12 February 2004 - 10:24 AM

That's excellent, thanks hollow.

RSS feed is just about ready to go live.
It's not the houses, it's the spaces between the houses.
akpcep.com - Everything | alexanderking.co - Me
0

#24 User is offline   hollow Icon

  • Group: Members
  • Posts: 1,772
  • Joined: 27-August 01
  • Location:Newcastle upon Tyne (UK)

Posted 12 February 2004 - 10:33 AM

Here's ALL of the ASCII characters, which proves that the above function is not quite complete, but good enough for every day use:

echo("<pre>");
for($i=0; $i<=256; $i++)
{
echo("<br/>".str_pad($i, 10)." ".chr($i));
}
echo("</pre>");
0

#25 User is offline   Green Mamba Icon

  • Group: Members
  • Posts: 84
  • Joined: 10-February 04
  • Location:3rd World
  • Interests:The Symbiosis of Life &amp; Death, Comics &amp; Web Design

Posted 12 February 2004 - 10:40 AM

Oh fuck ... and here I was thinking PHP shouldn't take me longer than a few weeks to master. At least, after three 2 hour sessions, I already understand what a function is...
0

#26 User is offline   Alexander Icon

  • Group: Admin
  • Posts: 3,097
  • Joined: 13-June 02
  • Gender:Male
  • Location:Your girlfriend's thoughts
  • Your fuckin' daddy

Posted 12 February 2004 - 10:45 AM

PHP, like anything, takes a long time to "master", but you can be building sites with it in a couple of weeks if you work hard at it. IMO.
It's not the houses, it's the spaces between the houses.
akpcep.com - Everything | alexanderking.co - Me
0

#27 User is offline   Anton Icon

  • Group: Donators
  • Posts: 1,611
  • Joined: 15-June 01
  • Gender:Male
  • Interests:"I sit around, watch TV, get high and talk bollocks." Anton circa 2009

    "I sit around, watch TV, get high, talk bollocks and play boardgames" Anton 2019

    That is what we call personal development.

Posted 12 February 2004 - 11:46 AM

Alexander, on Feb 12 2004, 11:31 AM, said:

PHP, like anything, takes a long time to "master", but you can be building sites with it in a couple of weeks if you work hard at it. IMO.

Damn straight, I must've spent all of 2 weeks learning PHP and I managed to code my own script to rip articles, names, dates etc. from the forum database I had set up to use it on the FP of my old site because I wasn't happy with the default.

If I, the most unmotivated person ever, can manage to do omething off my own back like that it can't be that difficult.
What was here before made me cringe and cry.
0

#28 User is offline   hollow Icon

  • Group: Members
  • Posts: 1,772
  • Joined: 27-August 01
  • Location:Newcastle upon Tyne (UK)

Posted 12 February 2004 - 12:20 PM

Yeah, it's more a matter of knowing where to look and what to look for when you've got a problem. Nine times out of ten it's a bloody semicolon that's causing all your problems.

For example, this won't do anything:

$hollow='class';
if($hollow=='class);
{
echo("Yep, hollow is class allright");
}

... and also knowing where to look for the functions you need. I find the windows help file, very handy indeed. You can download it here:

http://www.php.net/download-docs.php

This post has been edited by hollow: 12 February 2004 - 12:21 PM

0

#29 User is offline   hollow Icon

  • Group: Members
  • Posts: 1,772
  • Joined: 27-August 01
  • Location:Newcastle upon Tyne (UK)

Posted 12 February 2004 - 02:32 PM

The joys of back referencing regular exp​ressions:

<?PHP
$string="Prerequisites: ELL122, ELL111 or permission of module director";
$pattern = "/([a-zA-Z]{3}[0-9]{3})/i";
$replacement = "<a href=\"\\1.html\">\\1</a>";
echo preg_replace($pattern, $replacement, $string);
?>

Turns the university module codes into links because:

[a-zA-Z]{3}[0-9]{3} means three letters followed by three numbers.
( ) means store that lot in a variable
/i means case insensitive

and in the following line

\\1 means the first variable what you've stored. You can have more than one. This kind of thing is useful for automatically turn URL's into links and stuff.

http://uk.php.net/ma...reg-replace.php

This post has been edited by hollow: 12 February 2004 - 02:40 PM

0

#30 User is offline   Dragonfly Icon

  • Group: Members
  • Posts: 95
  • Joined: 23-April 03
  • Location:NYC

Posted 15 February 2004 - 05:42 PM

OK, I have a few questions about PHP:

1: What's debugging? When do I need it? And how do I do it or use the debugging script? How do I add it in and will it (and is it supposed to) stay in the final product?

2: If you can use echo either with or without brackets, what's the point in the brackets at all? Is it just leftover from old PHP, or do they still have some purpose?

3: If you can use either print or echo, when is it optimal to use which? What situations do each of them meet?

Thanks for any solutions for these little quizzes.
0

  • (3 Pages)
  • +
  • 1
  • 2
  • 3
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users