Re: [PHP] Replacing accented characters?

2010-01-28 Thread Marcus Gnaß
On 28.01.2010 03:40, Paul M Foster wrote:
 On Wed, Jan 27, 2010 at 04:55:46PM -0600, Skip Evans wrote:
 
 Hey all,

 I'm looking for recommendations on how to replace accented
 characters, like e and u with those two little dots above
 them, with the regular e and u characters.
 
 FWIW, those two dots are called an umlaut.
 
 Paul
 

FWIW, the whole letters ÄäÖöÜü are called Umlaute (umlauts).
The two dots above *these* letters are Umlautzeichen (umlaut marks).
But two dots above an e or i are called Trema (diacritic mark).

Marcus

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Question: Sorting through table headers?

2009-09-14 Thread Marcus Gnaß
Tony Marston wrote:

 You cannot do this in a separate class as it requires action in both the 
 presentation (UI) and data access layers, and a single class is not allowed 
 to operate in more than one layer.

You can, but you shouldn't if you want to write your classes according
to the MVC pattern.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Creating alphanumeric id for a table

2009-09-11 Thread Marcus Gnaß
aveev wrote:
 ?
 function generate_id($num) {
 $start_dig = 4;
 $num_dig = strlen($num);
 
 $id = $num;
 if($num_dig = $start_dig) {
 $num_zero = $start_dig - $num_dig;
 
 for($i=0;$i $num_zero; $i++) {
 $id = '0' . $id;
 }
 }
 $id = 'AAA' . $id;
 return $id;
 }
 
 $app_id = generate_id(1);
   
 ?

Your function can be reduced to a one-liner:

function generate_id($num) {
  return 'AAA' . str_pad(strval($num), 4, '0', STR_PAD_LEFT);
}

If the prefix is always 'AAA' you should consider to use a numeric ID
for your database and let your database generate the autoincrement id
and use this function just for display.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] header problem

2009-09-10 Thread Marcus Gnaß
A.a.k wrote:
 is there any alternative to header() for redirect users?

As far as I know there isn't.

Is the header-error the first error on the page? If not, the other error
message itself is the reason for the header-error and will be solved if
you solve the other error.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] SQL help?

2009-05-18 Thread Marcus Gnaß
Skip Evans wrote:
 Hey all,
 
 I have a SQL requirement I'm not quite sure how to compose.
 
 I have two tables, shows, and shows_dates. It's a one to many
 relationship where there is a single entry in shows and multiple entries
 in shows_dates that list each date and time for a play production for a
 run of entries in shows, like
 
 I need a query that will read each record in shows, but I only want the
 first record from shows_dates, the first one sorted by date, so I can
 display all shows in order of their opening date.
 
 Not sure how to grab just the first record from shows_dates though.
 
 Hint, anyone?
 
 Thanks,
 Skip
 


Join the two tables like you normally would do and aggregate the opening
date column with your dbms-specific max function and finally group the
result by a distinct value from shows.

It would have bee easier if you stated which rdbms you use ...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] speaking of control structures...

2009-05-06 Thread Marcus Gnaß
Tom Worster wrote:
 there's a control structure i wish php had: a simple block that you can
 break out of, e.g.


As Maarten pointed out you could use a function. Another alternative is
to use Exceptions which might be the most proper way to do it.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] speaking of control structures...

2009-05-06 Thread Marcus Gnaß
Robert Cummings wrote:
 On Wed, 2009-05-06 at 12:56 +0200, Marcus Gnaß wrote:
 Tom Worster wrote:
 there's a control structure i wish php had: a simple block that you can
 break out of, e.g.

 As Maarten pointed out you could use a function. Another alternative is
 to use Exceptions which might be the most proper way to do it.
 
 That seems like an abuse of exceptions. But then we're already abusing
 loops. I just don't think one could say it's the proper way to do it :)
 
 Cheers,
 Rob.

Why do you think it's an abuse of exceptions? If I have a block of code
which I expect to run from the beginning to the end and I discover a
situation wher its not appropriate to continue this block of code I is
what I would call an exception. Exception don't have to be errors or
such. It's just a special situation ...

Marcus

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] speaking of control structures...

2009-05-06 Thread Marcus Gnaß
Robert Cummings wrote:
 On Wed, 2009-05-06 at 22:23 +0200, Marcus Gnaß wrote:
 Robert Cummings wrote:
 On Wed, 2009-05-06 at 12:56 +0200, Marcus Gnaß wrote:
 Tom Worster wrote:
 there's a control structure i wish php had: a simple block that you can
 break out of, e.g.
 
 As Maarten pointed out you could use a function. Another alternative is
 to use Exceptions which might be the most proper way to do it.
 
 That seems like an abuse of exceptions. But then we're already abusing
 loops. I just don't think one could say it's the proper way to do it :)

 Why do you think it's an abuse of exceptions? If I have a block of code
 which I expect to run from the beginning to the end and I discover a
 situation where its not appropriate to continue this block of code I is
 what I would call an exception. Exception don't have to be errors or
 such. It's just a special situation ...
 
 While exceptions can certainly be used in this context and in a valid
 manner, there's a fine line between an exception and a condition. The OP
 was processing code that didn't appear exceptional, he was merely
 managing flow control of the logic. This is a condition, not an
 exception.

Agreed! He wrote:

if ( condition )
  break;

Although I had the impression that he expected the whole block of code
to be executed and just wanted to break from this block in an
exceptional situation.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] php forms - select menu selected behavior

2009-04-30 Thread Marcus Gnaß
Troy Oltmanns wrote:
 I have the code below being used to rifle through a list of available
 categories and create select options for them. The code is being used to
 query the database and compare the product category to the current
 iteration, if there's a match, then add selected code so the category is
 prechosen. More code (not included) does the saving and all that, I've check
 phpmyadmin. But when the page submits, the old category appears in the drop
 down as selected. If I leave the page and come back it's fine, it's just
 right after it is saved. The form script is being used on itself, in that
 there is only one file for the form, the submission, etc. All of the other
 input elements will load the data after being saved, is it something
 specific to dropdowns, or it is the way the code is being instatiated?
 
 All help is much appreciated. Please let me know if anymore info is needed.
 

//MAKE CATEGORIES DROPDOWN

$catlist1 = ;

// read product
$catmatch = SELECT prod_cat0 FROM product WHERE dbi='$dbi';;
$catresult = mysql_query($catmatch);
$catquery = mysql_fetch_array($catresult);

// read categories
$sql = SELECT category FROM categories ORDER BY category;;
$result = mysql_query($sql);
while ($col2 = mysql_fetch_array($result)) {

$id = $col2[category];

if ($id == $catquery['prod_cat0']){

$catlist1 .= option value=\$id\ 
selected=\selected\$id/option;

}   else {

$catlist1 .= option value=\$id\$id/option;

}

}

 
 to instantiate ?=$catlist1?
 

The only data you need from table product is the column prod_cat0, from
table categories it's category, so you should read only the needed data
instead of using * for better performance.

Take the SQL and verify if it returns what you want it to return then.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] A Tool For Building PHP Web Apps

2009-04-10 Thread Marcus Gnaß

Paul M Foster wrote:

On Fri, Apr 10, 2009 at 09:01:14AM -0400, Bob McConnell wrote:

  

From: Paul M Foster


Here's a hairbrained idea I was kicking around. I object to the idea
  

of


including 15 or 30 files in a PHP application just to display one page
on the internet. It makes the coding faster, but it makes the display
slower and seems silly to me.

So what if you had a tool or a set of tools where you could write code
snippets and such, and then hit a button or issue a command, and
everything you specified got written into a single file? You'd specify
that this page needs to read the config, set up a database connection,
validate these fields, etc. When you were done, it would write all
  

this


code to a *single* file, which the user would invoke by surfing to
  

that


page. The resulting code would be *static*, not like what results from
most templating systems. So rather than specify a specific variable
value in the resulting file, it would embed the PHP code to display
  

the


variable, etc.

What might be the liabilities of something like that? Would there be
security issues? Would there be increased difficulty in debugging?
  

What


can you think of?
  

Programs to do that used to be called compilers. There is an entire
branch of computer science and a lot of tools (lex, yacc, etc.)
dedicated to that topic.



I know compilers. I've coded in C for years. I'm not talking about a
compiler here. It's more an aggregator. The resulting page would still
be php/html, but everything needed in it would be self-contained (except
the web server and PHP interpreter). Kind of like what make does,
except that make typically invokes the compiler to mash it all into one
executable at the end.

  

It's not a bad idea, but there is one precarious assumption that
underlies it. Can you absolutely guarantee there will never be a second,
or third, or more pages on that server that will need some of those
functions or classes? As soon as the site begins to evolve and grow, you
will have multiple copies of many of those snippets, and when (not if)
you need to modify them, you will have to find and change every single
copy.

So you need to ask yourself if this strategy is maintainable in your
case. And will it make any real difference in the end?




Good point. That's why I asked the question in the first place. Every
time you revised a supporting file, you'd have to regenerate all the
files that depended on it. Might be okay for a small site, but could be
a nightmare for a large site.

Paul

  


You could try to substitute all your calls to include() or require() 
with SSI-includes and let your webserver do the aggregation then.


I read an article about retrieving the webservers result after 
performing SSI actions but before handing this over to the application 
server, but I can't remember where ...


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Question about template systems

2009-03-03 Thread Marcus Gnaß

Marcus Gnaß wrote:

like with programming questions in general.



Should have read my own post before sending! ;) Should be programming 
languages!


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Question about template systems

2009-03-03 Thread Marcus Gnaß

Matthew Croud wrote:

Hello,

First post here, I'm in the process of learning PHP , I'm digesting a 
few books as we speak.
I'm working on a content heavy website that provides a lot of 
information, a template system would be great and so i've been looking 
at ways to create dynamic data with a static navigation system.


So far, using the require_once(); function seems to fit the bill in 
order to bring in the same header html file on each page.

I've also looked at Smartys template system.

I wondered how you folk would go about creating a template system ?
Smarty is a good choice, although some people might prefer other 
templating systems. This is kind of a religious question like with 
programming questions in general. But I guess that most people would 
advise you to use an existing templating system instead of writing one 
on your own.
My second question might be me jumping the gun here, I haven't come 
across this part in my book but i'll ask about it anyway.  I often see 
websites that have a dynamic body and static header, and their web 
addresses end like this: index.php?id=445 where 445 i presume is 
some file reference.
What is this called ?  It seems like the system i'm after but it 
doesn't appear in my book,  If anyone could let me know what this page 
id subject is called i can do some research on the subject.
Have a look at the PHP manual and be sure to bookmark it! ;) 
http://www.php.net/manual/en/


The ID you mentioned is a query. id=445other_id=653 would be a 
querystring.
To retrieve data passed via this querystring you can use $_GET 
(http://de.php.net/manual/en/reserved.variables.get.php).



Have fun

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP OOP

2009-02-10 Thread Marcus Gnaß

Paul M Foster wrote:

On Mon, Feb 09, 2009 at 11:02:37AM -0500, tedd wrote:
  
As a side note, I think students should learn a language like C before

learning something like Perl, Python or PHP. Having to deal with
defining/declaring variables and their storage methods before use I
think makes for more conscientious programmers. And pointers are an
education all on their own. ;-}
  
For teaching programming or OOP I would choose a language which 
concentrates on the topic. The hard stuff, which you have to deal with 
in C for example, can be learned later. I'm glad that I started 
programming in Pascal, not in C. If today I had to learn programming as 
such I would definitively opt for Python! My choice for learning OOP 
would be Python or even better Java cause you don't have the choice to 
do it in a procedural way.


Marcus

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] maybe we could all?

2009-02-09 Thread Marcus Gnaß

Nathan Rixham wrote:

Project: PHP Common Objects and Datatypes


Has anything been setup for project COD-pieces yet? I like this name! ;)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] maybe we could all?

2009-02-09 Thread Marcus Gnaß

Nathan Rixham wrote:

Marcus Gnaß wrote:

Nathan Rixham wrote:

Project: PHP Common Objects and Datatypes


Has anything been setup for project COD-pieces yet? I like this name! ;)

Actually, yes it has - the project, well working group, has been 
called voom.

Sounds fine too! ;)
If you're interested just let me know and we'll get you introduced and 
set-up.
Yes please! I'm an intermediate PHP programmer who is lurking this list 
since october 06 and wrote a small CMS for my own (and a couple of 
friends) use so far.
I'm quite comfortable with (classical ... sigh) ASP so far which I use 
now for about 10 years and recently I began to get along with Java.


Your ideas sounded really great and I would like to join this group.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] colored text in images

2006-03-24 Thread Marcus Gnaß

Hi list!

I like to generate a larger image from different tiles. Each tile should 
have a text on it which should be red for better readability. I figured 
out how to compose the larger image but got stuck when to color the 
text. I tried the following code:


$img = imagecreate($w * 100, $h * 100);
$tile = imagecreatefromgif($tile_name);
$red = imagecolorallocate($tile, 255, 0, 0);
imagestring($tile, $font, $gebilde_x, $gebilde_y, $gebilde, $rot);
imagecopy($map, $tile, $dst_x, $dst_y, 0, 0, imagesx($tile), 
imagesy($tile));

header(Content-Type: image/gif);
imagegif($map);

The text was writte an expected, just it was grey and not red. What do I 
have to do to make it read and why was it grey?


Marcus

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php