Re: [PHP] Split

2011-12-13 Thread Dajka Tamás
Hi,

First, read the help of 'preg_replace' at php.net.

Second: try this: preg_split('/\//',$sPath,$iMax)
Third: use explode: explode('/',)

Cheers,

Tamas



2011.12.13. dátummal, 21:33 időpontban Jack jacklistm...@gmail.com írta:

 OK so I have seen enough errors about split, so I decided to update my code:
 
  return split(/, $sPath, $iMax);
 
 
 
 I tried:
 
 return preg_split(/, $sPath, $iMax);
 
 return preg_split(/, $sPath, $iMax, PREG_SPLIT_DELIM_CAPTURE);
 
 
 
 and a few other combinations, in the end always with errors. not sure I get
 the additional aspect.
 
 I do see ther error log it tells me no ending delimiter
 
 
 
 Any help appreciated.
 
 
 
 
 
 Thanks!
 
 Jack
 
 
 

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



RE: [PHP] PHP Version: 5.2.5.

2011-10-17 Thread Dajka Tamás
Hi,

PHP parser is not enabled ( module not enabled or not associated with
.php/.html/.htm files! )

Cheers,

Tamas

-Original Message-
From: Joseph Adenuga [mailto:jadenu...@yahoo.com] 
Sent: Monday, October 17, 2011 3:55 PM
To: php-general@lists.php.net
Cc: jadenu...@yahoo.com
Subject: [PHP] PHP Version: 5.2.5. 



Operating System: Window XP

PHP Version: 5.2.5. with Apache 2.2.8

My Firefox browser returns (Output) the same php script code I inserted in
Notepad:  ?php 

    echo h1Hello
Web!/h1; 

?

 

Please, what am I doing wrong?



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



RE: [PHP] Newbie question. What is the best structure of a php-app?

2011-08-16 Thread Dajka Tamás
Hi,

Surely there's a wiki/doc somewhere :)

But for the start:

1) plan what exactly you want to accomplish ( functionality )
2) complexity
- if simple, just throw it in one php ( like index.php )
- if more complex, you can separate the pages and/or use classes
3) based on 2), plan the structure ( I'm using mostly one entry point - 
index.php - with classes, templates, files included, since I like things 
separated )

Some thing you should not forget:
- whole webapp thing is event based ( client will do something - press a link - 
and the server will react ) - the connection is not maintained all the time
- PHP is server side (harder to debug), you cannot do anything on client side ( 
just push what to display ) ( JS is client side )
- you can start the session whenever you want ( it's nearly the first line of 
my app ), but you should control the access with variables, like if ( 
$_SESSION['uid'] ) or if ( $_SESSION['loggedin'] )
- most webservers interprets things between ?php ? even if the file name ends 
with .htm or .html
- for JS and connection related things FireBug for FireFox is a good idea ( you 
can track, what's submitted, etc )

What I'm liking:

- one entry point ( index.php )
- sub-pages, are separate php/template pairs BUT are included from index.php ( 
after access verification, etc )
- nearly all the functions are put in separate classes ( like user.class.php 
for user related things - login,logout, etc )
- using a template engine is not a very bad idea ( like Smarty ), you can 
separate the real code from html, which make debugging easier - at least for me 
:)

BTW, take a look on some free stuff. You can always learn from others. There 
are some good ideas in open CMS systems, like Joomla.


Cheers,

Tom

-Original Message-
From: Andreas [mailto:maps...@gmx.net] 
Sent: Tuesday, August 16, 2011 12:39 AM
To: php-general@lists.php.net
Subject: [PHP] Newbie question. What is the best structure of a php-app?

Hi,
I'm fairly new to PHP but not to programming as such. Currently I sat up 
XAMPP with xdebug, Netbeans and Eclipse to get a feeling.
I can write and run php-files but I am wondering how I should construct 
a more complex application that runs over several pages between a login 
and a logout.

How would I structure such an application so that it is possible to run 
it in the debugger from the beginning?
E.g. as a simple example I may build an index.html that has a menue with 
links to 3 php-files.
1)   login.php
2)   enter_data.php
3)   list_data.php
as html-links within an ul-list.

The user should at first click on login where user/password gets entered 
an a session starts.
Then the application comes back to index.html.
Now he might click 2) ...

Is it possible to run the whole application from the start on?
index.html is no php so xdebug won't process it and therefore the IDEs 
may start index.html but can't show the stage where the page is just 
waiting e.g. for a click on login and later branch for the other options.

Even if I write an index.php that shows the menue eventually the script 
just dumps the html that'll wait for the following clicks.
Those following steps are far more likely in need to be debugged.

Is it neccessary to debug those subpages separately even though they 
need prior steps like login.php that store some infos in a session or 
cookie that later scripts need to rely on?
Can I somehow watch what is going on from the index.html on?

Until now I just found documentation that explains the php language. 
Thats good too but I'd need to get an idea about the web-app-thinking 
that consist of just pages where the designer has to hope that the user 
stays within the applicationflow instead of clicking unexpectedly on the 
back-button or just jumping off to some other site if he likes to.

In contrast to this desktop-apps seem to be less demanding because I 
know where a user can navigate from a certain stage within the app and I 
could step from program start to stop with the debugger if I feel the 
need to.

Is there a tutorial that explains how to build consistent web-apps 
beyond the details of php language?


regards...

-- 
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



RE: [PHP] Problem with inserting numbers...

2011-08-11 Thread Dajka Tamás
While no tusing just one while loop?

$num = 0;
while ( ( $row = mysql_fetch_assoc($result) )  $num++ = 1000 ) {
//do whatever you want and you'll get all results or max. 1000 lines ( 
whatever comes first )
}

Cheers,

Tom

-Original Message-
From: Tim Streater [mailto:t...@clothears.org.uk] 
Sent: Thursday, August 11, 2011 11:22 AM
To: Jason Pruim
Cc: PHP General List
Subject: Re: [PHP] Problem with inserting numbers...

On 11 Aug 2011 at 02:22, Jason Pruim pru...@gmail.com wrote: 

 while ($num != 1) {
while($row = mysql_fetch_assoc($result)) {
$padnum = number_pad($num, 4);
echo $row['areacode'] . - . $row['prefix'] . - . $padnum . BR;
$num++;
}


 }

This is certain to fail. You've got the $num++ in the *inner* loop, and are 
checking its value in the *outer* loop. Think about it: suppose you enter the 
inner loop with $num being 9998. Suppose also that you then go round the inner 
loop 5 times. What is the value of $num when you then exit the inner loop in 
order to do the test against 1 in the outer loop?

You need to rework that logic.

--
Cheers  --  Tim



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



RE: [PHP] Struggling with MySQL query

2011-08-09 Thread Dajka Tamás
Or the query should look like this, if there is a 'headline' field:

UPPER(`headline`) LIKE '%.mysql_real_escape_string(trim(strtoupper($find))).%'

Cheers,

Tamas

-Original Message-
From: Andrew Ballard [mailto:aball...@gmail.com] 
Sent: Tuesday, August 09, 2011 4:55 PM
To: David Green
Cc: php-general@lists.php.net
Subject: Re: [PHP] Struggling with MySQL query

On Tue, Aug 9, 2011 at 10:14 AM, David Green simp...@gmail.com wrote:
[snip]
 $data = mysql_query(SELECT * FROM news_items WHERE upper('headline') LIKE
 '%$find%');

A couple things to consider.

First, as a few others have pointed out, you probably want to remove
the single quotes around the word headline in your query. The quotes
cause the query to compare the wildcard string '%{$find}%' to the
literal string 'headline' instead of the contents of a column named
headline. That would cause your query to return either no results for
ordinary search terms, or else return the entire table if the value of
$find is the word 'headline' or any sequence of characters within that
word.

You also probably don't need upper(...) function at all. Unless you
used a case-sensitive collation for that column/table (or are storing
it as binary data rather than text) the condition

'My Article Title' LIKE '%article%'

would return a match even though the case is different.

Andrew

-- 
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



RE: [PHP] Use of preg_replace

2011-07-24 Thread Dajka Tamás
Hi,

I lost trail, what do you want to do?

You want to convert

From

to this:

From

Or what's the goal?

Cheers,

Tamas

-Original Message-
From: Tim Streater [mailto:t...@clothears.org.uk] 
Sent: Sunday, July 24, 2011 8:07 PM
To: PHP General List
Subject: [PHP] Use of preg_replace

I need to be able to convert a line of the form:

From

to have either one more or one less  at the front. A web site tells me that 
the regexps to use are:

1,$s/^*From //

and

1,$s/^(*From )/\1/

respectively (there is a single space after From). So, if my text string is 
in $line, I ought to be able to do something like:

$line = preg_replace ($pattern, $replacement, $line);

But, since all regexps are to me, like TECO commands, no better than 
line-noise, how do I make up $pattern and $replacement from the proffered 
regexps?

Thanks.

--
Cheers  --  Tim



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



RE: RE: [PHP] Use of preg_replace

2011-07-24 Thread Dajka Tamás
You want to do it in a greater text, I think.


1,$s/^(*From )/\1/


$line = preg_replace ($pattern, $replacement, $line);


Adding one '':

preg_replace('/(^[]+From )/','$1', $line)

Removing one '':

preg_replace('/(^([]+From )/','$1', $line)

Cheers,

Tamas

-Original Message-
From: Tim Streater [mailto:t...@clothears.org.uk] 
Sent: Sunday, July 24, 2011 8:51 PM
To: Dajka Tamás; PHP General List
Subject: Re: RE: [PHP] Use of preg_replace

On 24 Jul 2011 at 19:35, Dajka Tamás vi...@vipernet.hu wrote: 

 I lost trail, what do you want to do?

 You want to convert

 From

 to this:

 From

The number of  in front of From  is not known. I want to be able to add or 
remove one.

--
Cheers  --  Tim



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



RE: [PHP] Foreach question

2011-07-06 Thread Dajka Tamás
And that's exactly how I did it :)

Since 'for' is traditionally pre-testing with excetuting the condition prior 
looping it's working well :)

Thanks for all the help!

Cheers,

Tamas

-Original Message-
From: Louis Huppenbauer [mailto:louis.huppenba...@gmail.com] 
Sent: Tuesday, July 05, 2011 5:47 PM
To: Robert Cummings
Cc: Dajka Tamás; php-general@lists.php.net
Subject: Re: [PHP] Foreach question

Just use count($arr) in your for-header, as it get's executed again
for each loop.

?php
   $arr = array(array('id'=1), array('id'=2));
for($i=0;$icount($arr);$i++) {
echo $arr[$i]['id'];
if($i  6) {
$arr[] = array('id' = $arr[$i]['id']+1);
}
}
?

2011/7/5 Robert Cummings rob...@interjinn.com:
 On 11-07-05 10:48 AM, Dajka Tamás wrote:

 Thanks, that was interesting :) I think I got one step further in
 understanding PHP :)

 BTW, I've changed the loop to 'for' and it's working well :)

 Can you show us your for loop? I'm not immediately sure how you use a for
 loop to traverse a growing number of entries in an array without either
 updating the extents of the traversal or using for( ; ; ) which is the same
 as while( 1 ). Or are you now using the low level array traversal functions
 like reset() and next()?

 Cheers,
 Rob.
 --
 E-Mail Disclaimer: Information contained in this message and any
 attached documents is considered confidential and legally protected.
 This message is intended solely for the addressee(s). Disclosure,
 copying, and distribution are prohibited unless authorized.

 --
 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



RE: [PHP] Foreach question

2011-07-05 Thread Dajka Tamás
Hi,

Yeah, I'm really want to do that, since I'm working with the elements of the 
original array ( skipped that part in sample code ).

I've tried your suggestion, but it gives the same result, so on just one input 
is just gives back '1'.

What troubles me, that foreach gives an inconsistent working. Why is 'foreach' 
checking element count at all and working differently with different element 
counts? That's not normal is my opinion. 'foreach' shouldn't do this:

if ( count($elements) == 1 ) then loop 1;
else loop normally;

and that's what is does now, since when it's more than one element it's working 
like a while loop, with checking the condition before ( and after ) every run. 
( if 'foreach' would check that the current run is the last one before 
executing the current loop, the results would be the same with each case )

Cheers,

Tamas

-Original Message-
From: Robert Cummings [mailto:rob...@interjinn.com] 
Sent: Tuesday, July 05, 2011 4:06 PM
To: Dajka Tamas
Cc: php-general@lists.php.net
Subject: Re: [PHP] Foreach question


On 11-07-05 09:40 AM, Dajka Tamas wrote:
 Hi all,



 I've bumped into an interesting thing with foreach. I really don't know, if
 this is normal working, or why it is, so I got curious.



 The script:



 foreach ( $cats as$c ) {

 echo $c['id'];

 if ( $c['id']  5 ) {

$c['id']++;

$cats[] = $c;

 }

 }

That's a bizarre loop... you're feeding references to elements of the 
array back into the array over which the loop is iterating. If you 
REALLY want to do what you are doing, then do the following:

?php

foreach( array_keys( $cats ) as $key )
{
 $c = $cats[$key];

 echo $c['id'];

 if( $c['id']  5 )
 {
 $c['id']++;
 $cats[] = $c;
 }
}

?

Cheers,
Rob.
-- 
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.


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



RE: [PHP] Foreach question

2011-07-05 Thread Dajka Tamás
Tried, gives the same result with one element :(

What's working:

$cats = array( array( 'id' = 1 ) );
while ( $c = array_shift($cats) ) {
echo $c['id'];
if ( $c['id']  5 ) {
$c['id']++;
$cats[] = $c;
}
}

But this is 'while' and it pops all elements from the array...

Cheers,

Tamas



-Original Message-
From: Louis Huppenbauer [mailto:louis.huppenba...@gmail.com] 
Sent: Tuesday, July 05, 2011 4:12 PM
To: Robert Cummings
Cc: Dajka Tamas; php-general@lists.php.net
Subject: Re: [PHP] Foreach question

Or maybe he tried to do the following?

?php
foreach ( $cats as$c ) {
   echo $c['id'];
   if ($c['id']  5) {
  $cats[] = array('id' = ($c['id'] + 1));
   }
}
?

2011/7/5 Robert Cummings rob...@interjinn.com:

 On 11-07-05 09:40 AM, Dajka Tamas wrote:

 Hi all,



 I've bumped into an interesting thing with foreach. I really don't know,
 if
 this is normal working, or why it is, so I got curious.



 The script:



 foreach ( $cats as$c ) {

echo $c['id'];

if ( $c['id']  5 ) {

   $c['id']++;

   $cats[] = $c;

}

 }

 That's a bizarre loop... you're feeding references to elements of the array
 back into the array over which the loop is iterating. If you REALLY want to
 do what you are doing, then do the following:

 ?php

 foreach( array_keys( $cats ) as $key )
 {
$c = $cats[$key];

echo $c['id'];

if( $c['id']  5 )
{
$c['id']++;
$cats[] = $c;
}
 }

 ?

 Cheers,
 Rob.
 --
 E-Mail Disclaimer: Information contained in this message and any
 attached documents is considered confidential and legally protected.
 This message is intended solely for the addressee(s). Disclosure,
 copying, and distribution are prohibited unless authorized.

 --
 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 General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Foreach question

2011-07-05 Thread Dajka Tamás
Ok, but if it would be that way I shouldn't get '122334455' for second output, 
no? The item count increments with every iteration of the loop.

Or you're saying that, it checks for an existance of nextitem before every 
loop, and that will fail with just one element, but will always return true 
with two elements? ( since the first elements copy is pushed as third element, 
etc )


-Original Message-
From: Robert Cummings [mailto:rob...@interjinn.com] 
Sent: Tuesday, July 05, 2011 4:28 PM
To: Dajka Tamás
Cc: php-general@lists.php.net
Subject: Re: [PHP] Foreach question

On 11-07-05 10:20 AM, Dajka Tamás wrote:
 Hi,

 Yeah, I'm really want to do that, since I'm working with the elements of the 
 original array ( skipped that part in sample code ).

 I've tried your suggestion, but it gives the same result, so on just one 
 input is just gives back '1'.

Ahhh... you want the behaviour of the multiple elements... I presumed 
you wanted the other way around.

 What troubles me, that foreach gives an inconsistent working. Why is 
 'foreach' checking element count at all and working differently with 
 different element counts? That's not normal is my opinion. 'foreach' 
 shouldn't do this:

 if ( count($elements) == 1 ) then loop 1;
 else loop normally;

 and that's what is does now, since when it's more than one element it's 
 working like a while loop, with checking the condition before ( and after ) 
 every run. ( if 'foreach' would check that the current run is the last one 
 before executing the current loop, the results would be the same with each 
 case )

You're making an assumption that it is checking the count. It may just 
be pre-determining whether another element exists for the next 
iteration. Consider the following pseudo code:

 nextItem = items-reset();
 while( nextItem )
 {
 item = nextItem;
 nextItem = items-next();

 // Do stuff.
 }

There's lots of ways to program a loop... and your PHP foreach loop is 
being converted to something entirely different internally. The above 
doesn't count elements, but it will result in the same behaviour as you 
are experiencing.

Cheers,
Rob.
-- 
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

-- 
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