Re: [PHP] find a word in a string

2008-11-06 Thread Amisha_Sharma

Hi 

Strstr fuction of PHP is used to find a string in another string
http://www.senpai-it.com/dedicated_servers.php 
Senpai IT Solutions  Dedicated Server at low cost 



Richard Kurth-2 wrote:
> 
> is the a php function to find a word in a string and report back that it 
> was found
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/find-a-word-in-a-string-tp20353971p20357047.html
Sent from the PHP - General mailing list archive at Nabble.com.


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



Re: [PHP] basic php question...

2008-11-06 Thread Amisha_Sharma

Hi  
What do you want to do on the another page?
you can also place a back link on that page to go back to previous page

http://www.senpai-it.com/dedicated_servers.php Senpai IT Solutions 
Dedicated Server at low cost 

bruce-60 wrote:
> 
> hi guys...
> 
> i've got a button that i want to select, and i want the app to process
> some
> logic, and then return the user to the page. my question is how??
> 
> something like
> 
> base page:
> 
>  foo.php button link" 
> 
> foo.php
>  -process logic
>  -return the user to the base page, with the same querystring that 
>   was initially used to generate the initial base page
> 
> 
> foo.php doesn't have any display function, just the logic 
> 
> thoughts/sample php pages/psuedo code chunks...
> 
> thanks
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

-- 
View this message in context: 
http://www.nabble.com/basic-php-question...-tp20329309p20357151.html
Sent from the PHP - General mailing list archive at Nabble.com.


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



Re: [PHP] Random number generator

2008-11-06 Thread Amisha_Sharma

Hi

you can use PHP rand() function for selecting a random number between 1 to
100.

http://www.senpai-it.com/dedicated_servers.php Senpai IT Solutions 
Dedicated Server at low cost  

WEISD wrote:
> 
> 
> On a php web page I want to generate a random number  between say 1 and 10 
> and then use that number to reference a particular file in an include tag.
> 
> 
> 
> Is there an easy way to do this?
> 
> Thanks 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Random-number-generator-tp20347780p20357212.html
Sent from the PHP - General mailing list archive at Nabble.com.


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



Re: [PHP] removing text from a string

2008-11-06 Thread Lupus Michaelis

Micah Gersten a écrit :


Yep, with a regex, it's real easy (untested code):


  So easy you got two bugs :




  I hope you don't really do that in production code. It can be bogus 
with big files.



$newFileData = preg_replace('/^\d+?\.\s?(.*$)/m','/$1/', $fileData);


  Buggy regex.

  And text,txt is a correct filename, I don't understand why you worry 
about :D


--
Mickaël Wolff aka Lupus Michaelis
http://lupusmic.org

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



Re: [PHP] removing text from a string

2008-11-06 Thread Lupus Michaelis

Ashley Sheridan a écrit :


Thats a lot of code when a couple of lines and a regex will do ;)


  Maybe because the use of the regex is pointless here. A bazooka to 
kill the fly ? :)


--
Mickaël Wolff aka Lupus Michaelis
http://lupusmic.org

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



Re: [PHP] basic php question...

2008-11-06 Thread Lupus Michaelis

Thodoris a écrit :

Do these people really exist? I though that their extinction happened 
the same with the dinosaurs.


  Like Ashley said it, they are some specific situation where you 
can't. But, Javascript can become a secrity issue, and it must be 
deactivable.


  Some years ago, they was a security issue about images in MSIE. To 
avoid any problems, images where filtered. Imagine to browse without 
images, when a great share of web sites uses images for their layout, 
and never cleanly fill the alt attribute ? It is the same with 
Javascript : it's a sugar.


--
Mickaël Wolff aka Lupus Michaelis
http://lupusmic.org

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



Re: [PHP] basic php question...

2008-11-06 Thread Richard Heyes
> * some proxy servers (e.g. at work) strip out some scripts

How on earth do you use Gmail? :-)

-- 
Richard Heyes

HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated November 1st)

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



Re: [PHP] building an admin tree with varying node types

2008-11-06 Thread Richard Heyes
> How are your groups linked with your users? Does every user has a GroupId in
> his record?

The code is not specifically related to a user management system, but
is something you can use to easily build such a system.

> Does this question has to do with building an html tree or it is about the
> best database schema that helps to construct and retrieve a tree faster?

The HTML_TreeMenu class will allow you to easily build a menu, and the
Tree class will help you easily build a tree structure to be used with
the former.

-- 
Richard Heyes

HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated November 1st)

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



Re: [PHP] building an admin tree with varying node types

2008-11-06 Thread Rene Veerman

Thodoris wrote:


How are your groups linked with your users? Does every user has a 
GroupId in his record?


Does this question has to do with building an html tree or it is about 
the best database schema that helps to construct and retrieve a tree 
faster?


My users-table is linked to the groups-table via a link table (2 fields, 
1 field in primary key).


This question is about how to manage "virtual" or "smart" node-items. 
Node-items that represent something in another table, that will likely 
change in that table. Like 'users' and 'groups' in the CMS.


The solution i'm trying now is to have certain root-nodes that get 
populated by a custom php abstraction layer.
Every node has a type, linking it to rights-management settings (and 
other things later i assume).
And every node has a 'target'. That links 1-to-many to records in 
tree_target_identifiers table. That table lists fields like table_name, 
key1_name, key1_value_int, key1_value_vc, etc. I have fields for 2 keys 
defined in that table.


Now the clue of this question is what to do when the user-list changes.
With my current solution, unless the user is actually deleted from the 
system, i wont have to make any changes to the admin tree, since the 
admin tree will get most of the 'data' for any node from the target 
tables, whether that be 'users', 'groups' or 'articles'.
If the user gets deleted, i could 
find-and-delete-the-corresponding-node, or i could rebuild that section 
of the tree (wont do that coz of resources and potential tree size).
But in any case the code that deletes a user, group, article, or any 
other object under the tree's management, will have to call code to 
update the tree aswell..

Sometimes theres just no way around hard work ;)

I've yet to experiment with nested trees and moving items between the 
nodes..



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



Re: [PHP] building an admin tree with varying node types

2008-11-06 Thread Rene Veerman

Thodoris wrote:


How are your groups linked with your users? Does every user has a 
GroupId in his record?


Does this question has to do with building an html tree or it is about 
the best database schema that helps to construct and retrieve a tree 
faster?




oh, and while searching i landed on a binary / modified-pre-ordered tree 
model, so i implemented that too.
bit worried about moving node-items, but i should be able to figure out 
a partial-update method.
holding my hands out for any examples/tutorials on how to do partial 
updates on a bin-tree when moving items..


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



Re: [PHP] removing text from a string

2008-11-06 Thread Thodoris



Thodoris wrote:
  

Boyd, Todd M. wrote:
 
  

-Original Message-
From: Ashley Sheridan [mailto:[EMAIL PROTECTED]
Sent: Tuesday, November 04, 2008 1:40 PM
To: Adam Williams
Cc: PHP General list
Subject: Re: [PHP] removing text from a string

On Tue, 2008-11-04 at 08:04 -0600, Adam Williams wrote:
 
  

I have a file that looks like:

1. Some Text here
2. Another Line of Text
3. Yet another line of text
340. All the way to number 340

And I want to remove the Number, period, and blank space at the



begining
 
  

of each line.  How can I accomplish this?

Opening the file to modify it is easy, I'm just lost at how to



remove
   


the text.:






I'd go with a regular expression any day for something like this.
Something like:

"/$[0-9]{1,3}\.\ .*^/g"

should do what you need. Note the space before the last period.
  
  

That would only work for files with 1-999 lines, and will wind up
matching the entire line (since you used $ and ^ and a greedy .*
inbetween... also... $ is "end-of-line" and ^ is "beginning-of-line" :))
rather than just the "line number" part. I would stick with my
originally-posted regex ("/^\d+\.\s/"), but I would modify yours like
this if I were to use it instead:

"/^[0-9]+\.\ (.*)$/" (What was the "g" modifier for, anyway?)

Then, you could grab the capture group made with (.*) and use it as the
"clean" data. (It would be group 1 in the match results and "$1" in a
preg_replace() call, I believe. Group 0 should be the entire match.)


Todd Boyd
Web Programmer




Personally, I would go this route if you wanted to stick with a regex.



This takes care of all possible issues related to the char after the
first period.  Maybe it is there maybe not.

Could be that it is a tab and not a space.  Could even be multiple
tabs or spaces.

  
  

There it goes again.

Every time someone asks a simple question (like the kind it's solved
with a simple trim, ltrim or rtrim) the discussion about which is the
best regular expression for this problem, makes a thread get "elephant"
sized :-) .

I love this list!!




Your not going to be able to get it with any of the xtrim() functions.  you 
would end up with various nested ltrim() calls that, IMO, would be a
nightmare to manage.

So, a top to bottom comparison here

If $line is this:
$line = '01. asdf';

And you use either one of these:
A) ltrim(ltrim(ltrim($line, '0123456789'), '.'));
B) preg_replace('/^[0-9]+\.\s*/', '', $line);

Which do you prefer?

A's Pros:
Not a regex
A's Cons:
A little slower then B
multiple function calls

B's Pros:
Slightly faster then A
Single Function call
B's Cons:
Regex



  


You should really check the manual again Jim. AFAIK ltrim doesn't remove 
a single character but as long they belong to the list they are all 
removed you just do:


ltrim($line, '0123456789')


and this does the job perfectly. So perhaps you need to reconsider your 
thoughts on this.


--
Thodoris



Re: [PHP] removing text from a string

2008-11-06 Thread Thodoris



Ashley Sheridan a écrit :


Thats a lot of code when a couple of lines and a regex will do ;)


  Maybe because the use of the regex is pointless here. A bazooka to 
kill the fly ? :)




I couldn't agree more. Not to mention that they are probably slower.

PS Don't get me wrong I like perl and pcre but it is pointless here.

--
Thodoris


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



Re: [PHP] ??????????? ??????? 648-67-61 ??? ?????? ? ???? ?????? ? ??????

2008-11-06 Thread Thodoris




On Wed, 2008-11-05 at 19:13 +0200, Thodoris wrote:
  

Command unkown. Make sure you typed it right.

  
  
Do you think that this cryptic number 648-67-61 has to do with the 
answer of all things? Like 42 for e.g.?


My russian (or whatever this is) suck more then  my English. That's a 
new experience, never felt it before.


--
Thodoris




I like how your email client has decimated the subject line! :p


Ash
www.ashleysheridan.co.uk


  


At least he asked me first and I was stupid enough to answer :-) .

--
Thodoris



Re: [PHP] building an admin tree with varying node types

2008-11-06 Thread Eric Butera
On Thu, Nov 6, 2008 at 5:08 AM, Rene Veerman <[EMAIL PROTECTED]> wrote:
> Thodoris wrote:
>>
>> How are your groups linked with your users? Does every user has a GroupId
>> in his record?
>>
>> Does this question has to do with building an html tree or it is about the
>> best database schema that helps to construct and retrieve a tree faster?
>>
>
> oh, and while searching i landed on a binary / modified-pre-ordered tree
> model, so i implemented that too.
> bit worried about moving node-items, but i should be able to figure out a
> partial-update method.
> holding my hands out for any examples/tutorials on how to do partial updates
> on a bin-tree when moving items..
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

I cheat and just keep the normal parentId column and regenerate the
tree based on changes on that.  I had spent a little bit looking at
the different update/delete methods and there wasn't a lot of good
information/examples as you've stated.  I had found some but there
were always edge cases that busted them.

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



Re: [PHP] basic php question... [compliance]

2008-11-06 Thread tedd

At 6:53 PM +0200 11/5/08, Thodoris wrote:

Thank you oh mighty and good God that I don't live in America!!

How do you manage all these strange things you guys ?


Nothing strange about it -- it's just the evolution of technology.

Things are improving for everyone. Certainly that does not mean it 
will be absent of growing pains, but today is better than it was 
yesterday. If nothing else, IE6 is less popular than it was.


Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] basic php question...

2008-11-06 Thread Thodoris




On Wed, 2008-11-05 at 18:48 +0200, Thodoris wrote:
  

Richard Heyes a écrit :
  

users who browse without Javascript enabled,
  

Heretics!



  No, paranoid :D

  
Do these people really exist? I though that their extinction happened 
the same with the dinosaurs.


--
Thodoris




Lots of reasons:

* some proxy servers (e.g. at work) strip out some scripts
  


Those evil netadmins should be blamed for this!!

* some mobile/text browsers don't have that option
  


Does anybody is really browsing from that kind of a phone ? Truly heretic!!

* some people do _really_ browse with it turned off!
  


Should be banished to outer space (links and lynx users are excluded).


Ash
www.ashleysheridan.co.uk

  


I think that I just got through a cultural shock :-) .

--
Thodoris



Re: [PHP] take me off the list

2008-11-06 Thread tedd

At 11:25 AM -0500 11/5/08, Dan Joseph wrote:

On Wed, Nov 5, 2008 at 11:18 AM, Robert Cummings <[EMAIL PROTECTED]>wrote:



 Isn't that redundant with the light him on fire option? With the light
 him on fire part he'll be warm for the rest of his life and then he
 won't bother anyone again :)



I've been trying to point that out in my signature for 3 years :)  I'm glad
someone finally realized it!


That should give you an idea of how many people read sigs.

I've seen a lot of cute ones over the years, but after the first 
couple of dozen times reading it, it loses it's charm/humor.


That's the reason why my sig only contains links where I'm trying to 
improve link popularity.


Cheers,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



[PHP] Globals or Super Global Variables To Be Reused from For Loops

2008-11-06 Thread Alice Wei

Hi, 

I have a snippet of code as shown in the following:

$message2="47406|Detroit";
$stringChunk2= explode("|", $message2);

 if ($message2!="") {
   $count_chunk2= count($stringChunk2);
   $count_chunk_2= $count_chunk2-1;
}

   for ($j=0; $j<$count_chunk2; $j++) {

  $string3= $stringChunk2[$j];   
  if ($j <$count_chunk_2) {
 $string2= " OR ";
 $string3=$string3.$string2;
   }
 else {
 //Don't do anything
   }
   echo $string3;
  }

The code itself works, but I would like to reuse $string3 variable somewhere 
else where I can build SQL statements from it. 
I tried using 

global $string3; 
echo $string3;

after the final curly brace, but I only get Detroit and not "47406 OR Detroit". 
Can anyone please suggest me what I should be using here?

Thanks for your help.

Alice

_
All-in-one security and maintenance for your PC.  Get a free 90-day trial!
http://www.windowsonecare.com/purchase/trial.aspx?sc_cid=wl_wlmail

Re: [PHP] Random number generator

2008-11-06 Thread Daniel P. Brown
On Thu, Nov 6, 2008 at 3:52 AM, Amisha_Sharma <[EMAIL PROTECTED]> wrote:
>
> Hi
>
> you can use PHP rand() function for selecting a random number between 1 to
> 100.

Amisha,

Welcome to the list, but please don't top post.  For a list of all
the guidelines for the official PHP lists, including this one, you can
check it out here:

http://www.php.net/reST/php-src/README.MAILINGLIST_RULES

-- 

http://www.parasane.net/
[EMAIL PROTECTED] || [EMAIL PROTECTED]
Ask me about our current hosting/dedicated server deals!

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



Re: [PHP] Globals or Super Global Variables To Be Reused from For Loops

2008-11-06 Thread Bastien Koert
[snip]
[/snip]

Alice,

The big problem here is that you are resetting the $string3 variable in the
loop

  for ($j=0; $j<$count_chunk2; $j++) {

 $string3= $stringChunk2[$j];//  <<<-- resetting
the value
 if ($j <$count_chunk_2) {
$string2= " OR ";
$string3=$string3.$string2;
  }
else {
//Don't do anything
  }
  echo $string3;
 }


I am not sure of your goal since you have not stated it, but it certainly
should be easier to just replace the PIPE  with the OR

$message = str_replace("|", " OR ", $message);



-- 

Bastien

Cat, the other other white meat


RE: 答复: 答复: [PHP]COOKIE or coding

2008-11-06 Thread Boyd, Todd M.
> -Original Message-
> From: Chris [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, November 05, 2008 8:51 PM
> To: Zhao chunliang[chunliang.zhao]
> Cc: php-general@lists.php.net
> Subject: Re: 答复: 答复: [PHP]COOKIE or coding
> 
> Zhao chunliang[chunliang.zhao] wrote:
> >
> > I'll use the string to decrypt, so that I want to they are the same.
> >
> > When I use 'urlencode', some other string will be changed. Like '/'
> 
> see also http://php.net/rawurlencode

...and if you're only worried about '+' to ' ', just replace!



That code should output:

'asldkf1231Qasasdf+123/Q==

HTH,


Todd Boyd
Web Programmer

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



RE: [PHP] Globals or Super Global Variables To Be Reused from For Loops

2008-11-06 Thread Alice Wei

Hi, 


  Sorry, I cannot use that because I am supposed to turn the string into 
something that looks like regions.name LIKE '%47406' OR regions.name LIKE 
'%Detroit', which I had to fix $string3 variable to   

  $string3="regions.name LIKE '%" . $stringChunk2[$j] . "'";

  The goal is that the $message variable would be only a $_POST['message'] 
variable so that the where clause can be generated dynamically. 
  The code I have above is part of my where clause in the full SQL statement I 
intend to
construct, which means I have to reuse this $string3 variable somewhere
else.
  
This is what my global declaration looks like: 

  if ($j <$count_chunk_2) {

 $string2= " OR ";
 $string3=$string3.$string2;
 global $string3;
   }
 else {
 //Don't do anything
   }
   echo $string3;
  }
echo $string3;

   The last $string3 echo only gives me regions.name
LIKE '%Detroit' according to the current construct and not regions.name
LIKE '%47406' OR regions.name LIKE '%Detroit'. Is there something else I should 
do to have it give me the same output as the echo $string3 as I have had after 
the second to last curly brace? 

Thanks again for your help.

Alice


> Date: Thu, 6 Nov 2008 10:22:44 -0500
> From: [EMAIL PROTECTED]
> To: [EMAIL PROTECTED]
> CC: php-general@lists.php.net
> Subject: Re: [PHP] Globals or Super Global Variables To Be Reused from For 
> Loops
> 
> [snip]
> [/snip]
> 
> Alice,
> 
> The big problem here is that you are resetting the $string3 variable in the
> loop
> 
>   for ($j=0; $j<$count_chunk2; $j++) {
> 
>  $string3= $stringChunk2[$j];//  <<<-- resetting
> the value
>  if ($j <$count_chunk_2) {
> $string2= " OR ";
> $string3=$string3.$string2;
>   }
> else {
> //Don't do anything
>   }
>   echo $string3;
>  }
> 
> 
> I am not sure of your goal since you have not stated it, but it certainly
> should be easier to just replace the PIPE  with the OR
> 
> $message = str_replace("|", " OR ", $message);
> 
> 
> 
> -- 
> 
> Bastien
> 
> Cat, the other other white meat

_
Express yourself with gadgets on Windows Live Spaces
http://discoverspaces.live.com?source=hmtag1&loc=us

Re: [PHP] removing text from a string

2008-11-06 Thread Jim Lucas
Thodoris wrote:
> 
>> Thodoris wrote:
>>  
 Boyd, Todd M. wrote:
  
  
>> -Original Message-
>> From: Ashley Sheridan [mailto:[EMAIL PROTECTED]
>> Sent: Tuesday, November 04, 2008 1:40 PM
>> To: Adam Williams
>> Cc: PHP General list
>> Subject: Re: [PHP] removing text from a string
>>
>> On Tue, 2008-11-04 at 08:04 -0600, Adam Williams wrote:
>>   
>>> I have a file that looks like:
>>>
>>> 1. Some Text here
>>> 2. Another Line of Text
>>> 3. Yet another line of text
>>> 340. All the way to number 340
>>>
>>> And I want to remove the Number, period, and blank space at the
>>> 
>> begining
>>   
>>> of each line.  How can I accomplish this?
>>>
>>> Opening the file to modify it is easy, I'm just lost at how to
>>> 
> remove
>   
>>> the text.:
>>>
>>> >> $filename = "results.txt";
>>>
>>> $fp = fopen($filename, "r") or die ("Couldn't open $filename");
>>> if ($fp)
>>> {
>>> while (!feof($fp))
>>> {
>>> $thedata = fgets($fp);
>>> //Do something to remove the "1. "
>>> //print the modified line and \n
>>> }
>>> fclose($fp);
>>> }
>>> ?>
>>>
>>> 
>> I'd go with a regular expression any day for something like this.
>> Something like:
>>
>> "/$[0-9]{1,3}\.\ .*^/g"
>>
>> should do what you need. Note the space before the last period.
>> 
> That would only work for files with 1-999 lines, and will wind up
> matching the entire line (since you used $ and ^ and a greedy .*
> inbetween... also... $ is "end-of-line" and ^ is
> "beginning-of-line" :))
> rather than just the "line number" part. I would stick with my
> originally-posted regex ("/^\d+\.\s/"), but I would modify yours like
> this if I were to use it instead:
>
> "/^[0-9]+\.\ (.*)$/" (What was the "g" modifier for, anyway?)
>
> Then, you could grab the capture group made with (.*) and use it as
> the
> "clean" data. (It would be group 1 in the match results and "$1" in a
> preg_replace() call, I believe. Group 0 should be the entire match.)
>
>
> Todd Boyd
> Web Programmer
>
> 
 Personally, I would go this route if you wanted to stick with a regex.

 >>>
 $lines[] = '01. asdf';
 $lines[] = '02. 323 asdf';
 $lines[] = '03.2323 asdf';
 $lines[] = '04. asdf 23';
 $lines[] = '05.asdf'; /* tabs used here */
 $lines[] = '06. asdf';

 foreach ( $lines AS $line ) {
 echo preg_replace('/^[0-9]+\.\s*/', '', $line), "\n";
 }

 ?>

 This takes care of all possible issues related to the char after the
 first period.  Maybe it is there maybe not.

 Could be that it is a tab and not a space.  Could even be multiple
 tabs or spaces.

 
>>> There it goes again.
>>>
>>> Every time someone asks a simple question (like the kind it's solved
>>> with a simple trim, ltrim or rtrim) the discussion about which is the
>>> best regular expression for this problem, makes a thread get "elephant"
>>> sized :-) .
>>>
>>> I love this list!!
>>>
>>> 
>>
>> Your not going to be able to get it with any of the xtrim()
>> functions.  you would end up with various nested ltrim() calls that,
>> IMO, would be a
>> nightmare to manage.
>>
>> So, a top to bottom comparison here
>>
>> If $line is this:
>> $line = '01. asdf';
>>
>> And you use either one of these:
>> A) ltrim(ltrim(ltrim($line, '0123456789'), '.'));
>> B) preg_replace('/^[0-9]+\.\s*/', '', $line);
>>
>> Which do you prefer?
>>
>> A's Pros:
>> Not a regex
>> A's Cons:
>> A little slower then B
>> multiple function calls
>>
>> B's Pros:
>> Slightly faster then A
>> Single Function call
>> B's Cons:
>> Regex
>>
>>
>>
>>   
> 
> You should really check the manual again Jim. AFAIK ltrim doesn't remove
> a single character but as long they belong to the list they are all
> removed you just do:
> 
> ltrim($line, '0123456789')
> 
> 
> and this does the job perfectly. So perhaps you need to reconsider your
> thoughts on this.
> 

Maybe instead of saying "AFAIK", you should go and check it yourself.  But 
obviously, since you didn't care to do it the first time around, I will
supply the relevant parts for you and the list archive.  And I quote:

Reference: http://us3.php.net/ltrim

Under "Returned Values" section...

Return Values

This function returns a string with whitespace stripped from the beginning of 
str . Without the second parameter, ltrim() will strip these characters:

* " " (ASCII 32 (0x20)), an ordinary space.
* "\t" (ASCII 9 (0x09)), a tab.
* "\n" (ASCII 10 (0x0A)), a new line (line feed).
* "\r" (ASCII 13 (0x0D

Re: [PHP] removing text from a string

2008-11-06 Thread Jim Lucas
Thodoris wrote:
> 
>> Ashley Sheridan a écrit :
>>
>>> Thats a lot of code when a couple of lines and a regex will do ;)
>>
>>   Maybe because the use of the regex is pointless here. A bazooka to
>> kill the fly ? :)
>>
> 
> I couldn't agree more. Not to mention that they are probably slower.
> 
> PS Don't get me wrong I like perl and pcre but it is pointless here.
> 

Personal choice, and yes my testing has proven that a regex is faster then the 
multiple function calls or if conditions needed to accomplish the same
thing.

-- 
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare


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



RE: [PHP] removing text from a string

2008-11-06 Thread Boyd, Todd M.
> -Original Message-
> From: Jim Lucas [mailto:[EMAIL PROTECTED]
> Sent: Thursday, November 06, 2008 9:58 AM
> To: [EMAIL PROTECTED]
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] removing text from a string
> 
> Thodoris wrote:
> >
> >> Ashley Sheridan a écrit :
> >>
> >>> Thats a lot of code when a couple of lines and a regex will do ;)
> >>
> >>   Maybe because the use of the regex is pointless here. A bazooka to
> >> kill the fly ? :)
> >>
> >
> > I couldn't agree more. Not to mention that they are probably slower.
> >
> > PS Don't get me wrong I like perl and pcre but it is pointless here.
> >
> 
> Personal choice, and yes my testing has proven that a regex is faster
> then the multiple function calls or if conditions needed to accomplish
> the same
> thing.

Yeah, I think people under-estimate the performance of (SIMPLE) Regular 
Expressions for text manipulation and searching. As long as you don't have like 
15 nested groups and callbacks and optional chars/groups out the wazoo in your 
PCRE pattern, it will be very quick: it was designed with efficiency and speed 
in mind.

I feel it's also worth mentioning that it may be worthwhile to lean towards 
RegEx functions for text searching/manipulation so that there is a consistency 
between methods throughout your code. 15 regex patterns may be better than 
intermingling xtrim(), strstr(), stripos(), str_replace(), etc... and are 
probably more easily-readable than scanning 15 10-line algorithms to discern 
their purpose.

Just a thought.


Todd Boyd
Web Programmer
RegEx Fan (but not Fanatic)

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



Re: [PHP] Random number generator

2008-11-06 Thread Andrew Ballard
On Thu, Nov 6, 2008 at 10:53 AM, WEISD <[EMAIL PROTECTED]> wrote:
>
> ""Gary M. Josack"" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>>
>> Stephen wrote:

 On a php web page I want to generate a random number between say 1 and
 10 and then use that number to reference a particular file in
 an include tag.

 

 Is there an easy way to do this?

>>>
>>> Get the time and use the last digit converting 0 to 10.
>>>
>>> Stephen
>>>
>>>
>> rand(1, 10);
>
> Thanks for the help!!
>
> php's random number generator seems to have favorite numbers.
>
> rand(1, 10);  produces 10 & 3, 90% of the time
>

That is strange. I get pretty balanced results on this computer.



Array
(
[1] => 19991 (10.00%)
[2] => 19981 (9.99%)
[3] => 20011 (10.01%)
[4] => 19998 (10.00%)
[5] => 20049 (10.02%)
[6] => 20008 (10.00%)
[7] => 19983 (9.99%)
[8] => 19986 (9.99%)
[9] => 20007 (10.00%)
[10] => 19986 (9.99%)
)

Andrew

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



Re: [PHP] Globals or Super Global Variables To Be Reused from For Loops

2008-11-06 Thread Jim Lucas
Alice Wei wrote:
> Hi, 
> 
> 
>   Sorry, I cannot use that because I am supposed to turn the string into 
> something that looks like

Sounds like we are doing someones school work again.

> regions.name LIKE '%47406' OR regions.name LIKE '%Detroit', which I had to 
> fix $string3 variable to   
> 
>   $string3="regions.name LIKE '%" . $stringChunk2[$j] . "'";
> 
>   The goal is that the $message variable would be only a $_POST['message'] 
> variable so that the where clause can be generated dynamically. 
>   The code I have above is part of my where clause in the full SQL statement 
> I intend to
> construct, which means I have to reuse this $string3 variable somewhere
> else.
>   
> This is what my global declaration looks like: 
> 
>   if ($j <$count_chunk_2) {
> 
>  $string2= " OR ";
>  $string3=$string3.$string2;
>  global $string3;
>}
>  else {
>  //Don't do anything
>}
>echo $string3;
>   }
> echo $string3;

against my better judgment, I believe this is what you are looking for.

# Get your starting string
$pieces = "47406|Detroit";

# Break it into the parts you are looking to use
$parts  = explode("|", $pieces);

# Empty temporary array
$tmpHolder = array();

# Loop through parts list
foreach ( $parts AS $part ) {

# Create a single statement and stuff it in your tmp array
$tmpHolder[] = "regions.name LIKE '%{$part}'";
}

# Join all the parts together, placing an OR between each element.
$string3 = join(' OR ', $tmpHolder);


> 
>The last $string3 echo only gives me regions.name
> LIKE '%Detroit' according to the current construct and not regions.name
> LIKE '%47406' OR regions.name LIKE '%Detroit'. Is there something else I 
> should do to have it give me the same output as the echo $string3 as I have 
> had after the second to last curly brace? 
> 
> Thanks again for your help.
> 
> Alice
> 
> 
>> Date: Thu, 6 Nov 2008 10:22:44 -0500
>> From: [EMAIL PROTECTED]
>> To: [EMAIL PROTECTED]
>> CC: php-general@lists.php.net
>> Subject: Re: [PHP] Globals or Super Global Variables To Be Reused from For 
>> Loops
>>
>> [snip]
>> [/snip]
>>
>> Alice,
>>
>> The big problem here is that you are resetting the $string3 variable in the
>> loop
>>
>>   for ($j=0; $j<$count_chunk2; $j++) {
>>
>>  $string3= $stringChunk2[$j];//  <<<-- resetting
>> the value
>>  if ($j <$count_chunk_2) {
>> $string2= " OR ";
>> $string3=$string3.$string2;
>>   }
>> else {
>> //Don't do anything
>>   }
>>   echo $string3;
>>  }
>>
>>
>> I am not sure of your goal since you have not stated it, but it certainly
>> should be easier to just replace the PIPE  with the OR
>>
>> $message = str_replace("|", " OR ", $message);
>>
>>
>>
>> -- 
>>
>> Bastien
>>
>> Cat, the other other white meat
> 
> _
> Express yourself with gadgets on Windows Live Spaces
> http://discoverspaces.live.com?source=hmtag1&loc=us


-- 
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare


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



Re: [PHP] take me off the list

2008-11-06 Thread Dan Joseph
On Thu, Nov 6, 2008 at 9:17 AM, tedd <[EMAIL PROTECTED]> wrote:

>
> I've been trying to point that out in my signature for 3 years :)  I'm glad
>> someone finally realized it!
>>
>
> That should give you an idea of how many people read sigs.
>
> I've seen a lot of cute ones over the years, but after the first couple of
> dozen times reading it, it loses it's charm/humor.
>
> That's the reason why my sig only contains links where I'm trying to
> improve link popularity.
>

Yeah... I noticed people stopped reading sigs back in the late 90s when the
whole awe of the internet wore off.  I think I'm one of the last few that
actually do look at 'em.  I stuck my web site in my sig when we opened for
business last spring for the same reason.

-- 
-Dan Joseph

www.canishosting.com - Plans start @ $1.99/month.

"Build a man a fire, and he will be warm for the rest of the day.
Light a man on fire, and will be warm for the rest of his life."


Re: [PHP] removing text from a string

2008-11-06 Thread Richard Heyes
> RegEx Fan

Seriously...?

-- 
Richard Heyes

HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated November 1st)

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



Re: [PHP] Random number generator

2008-11-06 Thread WEISD


""Gary M. Josack"" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

Stephen wrote:
On a php web page I want to generate a random number between say 1 and 
10 and then use that number to reference a particular file in

an include tag.



Is there an easy way to do this?



Get the time and use the last digit converting 0 to 10.

Stephen



rand(1, 10);


Thanks for the help!!

php's random number generator seems to have favorite numbers.

rand(1, 10);  produces 10 & 3, 90% of the time 



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



RE: [PHP] Random number generator

2008-11-06 Thread Jay Blanchard
[snip]


You can see it in action here at the bottom of the page there is a
footer. 
Each footer is the same right now except I have numbered them for
testing.

As I refresh the page,  I get footer10 almost always with an occasional
2 or 
4 here and there...
[/snip]

So there fore it is random, or at least as random as it can be. If you
want it to be random but not be the same as the last value generated you
have to do some more complex programming. But then you have really made
things less random. 

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



Re: [PHP] Random number generator

2008-11-06 Thread Stephen
On Thu, 11/6/08, WEISD <[EMAIL PROTECTED]> wrote:

> > That is strange. I get pretty balanced results on this
> computer.
> >
> >  >
> > $histogram = array_fill(1, 10, 0);
> >
> > $iterations = 20;
> >
> > for ($i = 0; $i < $iterations; ++$i) {
> >++$histogram[round(rand(1, 10))];
> > }
> >
> > print_r($histogram);
> >
> > ?>
> >
> > Andrew
> 
> Simple code,
> 
>  $number = rand(1, 10);
> 
> include("footer$number.html"); ?>
> 
> You can see it in action here at the bottom of the page
> there is a footer. 
> Each footer is the same right now except I have numbered
> them for testing.
> 
> As I refresh the page,  I get footer10 almost always with
> an occasional 2 or 
> 4 here and there...
> 
> http://www.weisd.com/store2/WINHD-9022.php

Computer functions to generate random numbers are not designed to do what their 
name suggests.

Software testing requires repeatability, and this includes random number 
generation.

Without knowing how PHP seeds the generator it is difficult to predict what it 
will do.

I still think taking the last digit of the current time is your best solution.

Stephen

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



Re: [PHP] Random number generator

2008-11-06 Thread Micah Gersten
WEISD wrote:
>
>> That is strange. I get pretty balanced results on this computer.
>>
>> >
>> $histogram = array_fill(1, 10, 0);
>>
>> $iterations = 20;
>>
>> for ($i = 0; $i < $iterations; ++$i) {
>>++$histogram[round(rand(1, 10))];
>> }
>>
>> print_r($histogram);
>>
>> ?>
>>
>> Andrew
>
> Simple code,
>
>  $number = rand(1, 10);
>
> include("footer$number.html"); ?>
>
> You can see it in action here at the bottom of the page there is a
> footer. Each footer is the same right now except I have numbered them
> for testing.
>
> As I refresh the page,  I get footer10 almost always with an
> occasional 2 or 4 here and there...
>
> http://www.weisd.com/store2/WINHD-9022.php
>
>
>

Which PHP version are you running?  After 4.2.0, it should be random
each call.  Otherwise, use srand();

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



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



Re: [PHP] Random number generator

2008-11-06 Thread WEISD




Computer functions to generate random numbers are not designed to do what 
their name suggests.


Software testing requires repeatability, and this includes random number 
generation.


Without knowing how PHP seeds the generator it is difficult to predict 
what it will do.


I still think taking the last digit of the current time is your best 
solution.


Stephen


I like the idea of using the time but don't like the idea of spending the 
rest of the day learning how to parse out the numbers I need from the 
time... 



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



Re: [PHP] Random number generator

2008-11-06 Thread WEISD



That is strange. I get pretty balanced results on this computer.



Andrew


Simple code,



You can see it in action here at the bottom of the page there is a footer. 
Each footer is the same right now except I have numbered them for testing.


As I refresh the page,  I get footer10 almost always with an occasional 2 or 
4 here and there...


http://www.weisd.com/store2/WINHD-9022.php




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



Re: [PHP] Random number generator

2008-11-06 Thread Maciek Sokolewicz

WEISD wrote:




Computer functions to generate random numbers are not designed to do 
what their name suggests.


Software testing requires repeatability, and this includes random 
number generation.


Without knowing how PHP seeds the generator it is difficult to predict 
what it will do.


I still think taking the last digit of the current time is your best 
solution.


Stephen


I like the idea of using the time but don't like the idea of spending 
the rest of the day learning how to parse out the numbers I need from 
the time...


1. change the number to a string: $t = (string) time();
2. chop off the last char of the string: $char = substr($t, -1);
3. you're done...: include "footer$char.html";

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



Re: [PHP] Random number generator

2008-11-06 Thread Jim Lucas
WEISD wrote:
> 
>>
>> Computer functions to generate random numbers are not designed to do
>> what their name suggests.
>>
>> Software testing requires repeatability, and this includes random
>> number generation.
>>
>> Without knowing how PHP seeds the generator it is difficult to predict
>> what it will do.
>>
>> I still think taking the last digit of the current time is your best
>> solution.
>>
>> Stephen
> 
> I like the idea of using the time but don't like the idea of spending
> the rest of the day learning how to parse out the numbers I need from
> the time...
> 

Really, you think this step is difficult?

Try looking at the page http://php.net/date it will give you all that you need.

$second = (int)date('s');

This will give you the current second of the current minute of the current 

Anyways.

Take that and run it through a modulo then add one to keep it within the 1-10.



This should do

-- 
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare


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



Re: [PHP] Random number generator

2008-11-06 Thread tedd

At 10:30 AM -0600 11/6/08, WEISD wrote:
You can see it in action here at the bottom of the page there is a 
footer. Each footer is the same right now except I have numbered 
them for testing.


As I refresh the page,  I get footer10 almost always with an 
occasional 2 or 4 here and there...


http://www.weisd.com/store2/WINHD-9022.php



Not me -- I get a normal distribution.

Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] Random number generator

2008-11-06 Thread WEISD





http://www.weisd.com/store2/WINHD-9022.php



Not me -- I get a normal distribution.

Cheers,

tedd



Thanks Tedd,  That is because it is using  time now and not rand...


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



RE: [PHP] removing text from a string

2008-11-06 Thread Boyd, Todd M.
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
> Behalf Of Richard Heyes
> Sent: Thursday, November 06, 2008 10:26 AM
> To: Boyd, Todd M.
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] removing text from a string
> 
> > RegEx Fan
> 
> Seriously...?

Let's just say I wouldn't kick it out of bed for eating crackers.

Nice eye on the sig-watch, BTW. ;)


Todd Boyd
Web Programmer

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



Re: [PHP] Random number generator

2008-11-06 Thread Micah Gersten
Stephen wrote:
> On Thu, 11/6/08, WEISD <[EMAIL PROTECTED]> wrote:
>
>   
>>> That is strange. I get pretty balanced results on this
>>>   
>> computer.
>> 
>>> >>
>>> $histogram = array_fill(1, 10, 0);
>>>
>>> $iterations = 20;
>>>
>>> for ($i = 0; $i < $iterations; ++$i) {
>>>++$histogram[round(rand(1, 10))];
>>> }
>>>
>>> print_r($histogram);
>>>
>>> ?>
>>>
>>> Andrew
>>>   
>> Simple code,
>>
>> > $number = rand(1, 10);
>>
>> include("footer$number.html"); ?>
>>
>> You can see it in action here at the bottom of the page
>> there is a footer. 
>> Each footer is the same right now except I have numbered
>> them for testing.
>>
>> As I refresh the page,  I get footer10 almost always with
>> an occasional 2 or 
>> 4 here and there...
>>
>> http://www.weisd.com/store2/WINHD-9022.php
>> 
> Computer functions to generate random numbers are not designed to do what 
> their name suggests.
>
> Software testing requires repeatability, and this includes random number 
> generation.
>
> Without knowing how PHP seeds the generator it is difficult to predict what 
> it will do.
>
> I still think taking the last digit of the current time is your best solution.
>
> Stephen
>
>   
The PHP developers understood the random problem and the need for
predictability, so they did 2 things. 
1.  Randomly seed the random number generator every time
2.  Allow you to set the seed for predictability

http://us.php.net/srand

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



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



Re: [PHP] Random number generator

2008-11-06 Thread WEISD


1. change the number to a string: $t = (string) time();
2. chop off the last char of the string: $char = substr($t, -1);
3. you're done...: include "footer$char.html";



Time wins  certainly produces better results, at least for what I am 
doing, than rand...


Thanks all for your input...

Nice NG here 



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



RE: [PHP] Globals or Super Global Variables To Be Reused from For Loops

2008-11-06 Thread Alice Wei

Hi, 

  Thanks for your tip, and I am surprised that this could be done so easily. 

Alice

> Date: Thu, 6 Nov 2008 08:11:48 -0800
> From: [EMAIL PROTECTED]
> To: [EMAIL PROTECTED]
> CC: [EMAIL PROTECTED]; php-general@lists.php.net
> Subject: Re: [PHP] Globals or Super Global Variables To Be Reused from For 
> Loops
> 
> Alice Wei wrote:
> > Hi, 
> > 
> > 
> >   Sorry, I cannot use that because I am supposed to turn the string into 
> > something that looks like
> 
> Sounds like we are doing someones school work again.
> 
> > regions.name LIKE '%47406' OR regions.name LIKE '%Detroit', which I had to 
> > fix $string3 variable to   
> > 
> >   $string3="regions.name LIKE '%" . $stringChunk2[$j] . "'";
> > 
> >   The goal is that the $message variable would be only a $_POST['message'] 
> > variable so that the where clause can be generated dynamically. 
> >   The code I have above is part of my where clause in the full SQL 
> > statement I intend to
> > construct, which means I have to reuse this $string3 variable somewhere
> > else.
> >   
> > This is what my global declaration looks like: 
> > 
> >   if ($j <$count_chunk_2) {
> > 
> >  $string2= " OR ";
> >  $string3=$string3.$string2;
> >  global $string3;
> >}
> >  else {
> >  //Don't do anything
> >}
> >echo $string3;
> >   }
> > echo $string3;
> 
> against my better judgment, I believe this is what you are looking for.
> 
> # Get your starting string
> $pieces = "47406|Detroit";
> 
> # Break it into the parts you are looking to use
> $parts  = explode("|", $pieces);
> 
> # Empty temporary array
> $tmpHolder = array();
> 
> # Loop through parts list
> foreach ( $parts AS $part ) {
> 
>   # Create a single statement and stuff it in your tmp array
>   $tmpHolder[] = "regions.name LIKE '%{$part}'";
> }
> 
> # Join all the parts together, placing an OR between each element.
> $string3 = join(' OR ', $tmpHolder);
> 
> 
> > 
> >The last $string3 echo only gives me regions.name
> > LIKE '%Detroit' according to the current construct and not regions.name
> > LIKE '%47406' OR regions.name LIKE '%Detroit'. Is there something else I 
> > should do to have it give me the same output as the echo $string3 as I have 
> > had after the second to last curly brace? 
> > 
> > Thanks again for your help.
> > 
> > Alice
> > 
> > 
> >> Date: Thu, 6 Nov 2008 10:22:44 -0500
> >> From: [EMAIL PROTECTED]
> >> To: [EMAIL PROTECTED]
> >> CC: php-general@lists.php.net
> >> Subject: Re: [PHP] Globals or Super Global Variables To Be Reused from For 
> >> Loops
> >>
> >> [snip]
> >> [/snip]
> >>
> >> Alice,
> >>
> >> The big problem here is that you are resetting the $string3 variable in the
> >> loop
> >>
> >>   for ($j=0; $j<$count_chunk2; $j++) {
> >>
> >>  $string3= $stringChunk2[$j];//  <<<-- 
> >> resetting
> >> the value
> >>  if ($j <$count_chunk_2) {
> >> $string2= " OR ";
> >> $string3=$string3.$string2;
> >>   }
> >> else {
> >> //Don't do anything
> >>   }
> >>   echo $string3;
> >>  }
> >>
> >>
> >> I am not sure of your goal since you have not stated it, but it certainly
> >> should be easier to just replace the PIPE  with the OR
> >>
> >> $message = str_replace("|", " OR ", $message);
> >>
> >>
> >>
> >> -- 
> >>
> >> Bastien
> >>
> >> Cat, the other other white meat
> > 
> > _
> > Express yourself with gadgets on Windows Live Spaces
> > http://discoverspaces.live.com?source=hmtag1&loc=us
> 
> 
> -- 
> Jim Lucas
> 
>"Some men are born to greatness, some achieve greatness,
>and some have greatness thrust upon them."
> 
> Twelfth Night, Act II, Scene V
> by William Shakespeare
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

_
Express yourself with gadgets on Windows Live Spaces
http://discoverspaces.live.com?source=hmtag1&loc=us

Re: [PHP] removing text from a string

2008-11-06 Thread Thodoris



Thodoris wrote:
  

Thodoris wrote:
 
  

Boyd, Todd M. wrote:
 
 
  

-Original Message-
From: Ashley Sheridan [mailto:[EMAIL PROTECTED]
Sent: Tuesday, November 04, 2008 1:40 PM
To: Adam Williams
Cc: PHP General list
Subject: Re: [PHP] removing text from a string

On Tue, 2008-11-04 at 08:04 -0600, Adam Williams wrote:
  
  

I have a file that looks like:

1. Some Text here
2. Another Line of Text
3. Yet another line of text
340. All the way to number 340

And I want to remove the Number, period, and blank space at the



begining
  
  

of each line.  How can I accomplish this?

Opening the file to modify it is easy, I'm just lost at how to



remove
  


the text.:






I'd go with a regular expression any day for something like this.
Something like:

"/$[0-9]{1,3}\.\ .*^/g"

should do what you need. Note the space before the last period.

  

That would only work for files with 1-999 lines, and will wind up
matching the entire line (since you used $ and ^ and a greedy .*
inbetween... also... $ is "end-of-line" and ^ is
"beginning-of-line" :))
rather than just the "line number" part. I would stick with my
originally-posted regex ("/^\d+\.\s/"), but I would modify yours like
this if I were to use it instead:

"/^[0-9]+\.\ (.*)$/" (What was the "g" modifier for, anyway?)

Then, you could grab the capture group made with (.*) and use it as
the
"clean" data. (It would be group 1 in the match results and "$1" in a
preg_replace() call, I believe. Group 0 should be the entire match.)


Todd Boyd
Web Programmer




Personally, I would go this route if you wanted to stick with a regex.



This takes care of all possible issues related to the char after the
first period.  Maybe it is there maybe not.

Could be that it is a tab and not a space.  Could even be multiple
tabs or spaces.


  

There it goes again.

Every time someone asks a simple question (like the kind it's solved
with a simple trim, ltrim or rtrim) the discussion about which is the
best regular expression for this problem, makes a thread get "elephant"
sized :-) .

I love this list!!




Your not going to be able to get it with any of the xtrim()
functions.  you would end up with various nested ltrim() calls that,
IMO, would be a
nightmare to manage.

So, a top to bottom comparison here

If $line is this:
$line = '01. asdf';

And you use either one of these:
A) ltrim(ltrim(ltrim($line, '0123456789'), '.'));
B) preg_replace('/^[0-9]+\.\s*/', '', $line);

Which do you prefer?

A's Pros:
Not a regex
A's Cons:
A little slower then B
multiple function calls

B's Pros:
Slightly faster then A
Single Function call
B's Cons:
Regex



  
  

You should really check the manual again Jim. AFAIK ltrim doesn't remove
a single character but as long they belong to the list they are all
removed you just do:

ltrim($line, '0123456789')


and this does the job perfectly. So perhaps you need to reconsider your
thoughts on this.




Maybe instead of saying "AFAIK", you should go and check it yourself.  But 
obviously, since you didn't care to do it the first time around, I will
supply the relevant parts for you and the list archive.  And I quote:

Reference: http://us3.php.net/ltrim

Under "Returned Values" section...

Return Values

This function returns a string with whitespace stripped from the beginning of 
str . Without the second parameter, ltrim() will strip these characters:

* " " (ASCII 32 (0x20)), an ordinary space.
* "\t" (ASCII 9 (0x09)), a tab.
* "\n" (ASCII 10 (0x0A)), a new line (line feed).
* "\r" (ASCII 13 (0x0D)), a carriage return.
* "\0" (ASCII 0 (0x00)), the NUL-byte.
* "\x0B" (ASCII 11 (0x0B)), a vertical tab.

Notice the second sentence of the first line?
"Without the second parameter, ltrim() will strip these characters"

That means their is a default set of chars that it uses IF you do not supply a 
list of chars.

On a side note.  If you notice, under the ChangeLog section, the second 
parameter wasn't added until PHP 4.1.0.

What you said was "if they belong to the list they are all removed."  Then what 
exactly did this this function do before 4.1?

I did my requested homework, but I think you need to go back and study that 
chapter now.

  


This :

ltrim($line, '0123456789 .');


does remove all those characters doesn't it (as the OP asked and Richard 
suggested on a previous thread). Without calling it more than once as 
far as I tested. That was my point on the first place and sorry if I 
didn't make that clear. On the other hand who ever suggested calling 
ltrim without the second parameter.


You suggested before something like that:

ltrim(ltrim(ltrim($line, '0123456789'), '.'))


when you 

Re: [PHP] removing text from a string

2008-11-06 Thread Thodoris



Thodoris wrote:
  

Ashley Sheridan a écrit :

  

Thats a lot of code when a couple of lines and a regex will do ;)


  Maybe because the use of the regex is pointless here. A bazooka to
kill the fly ? :)

  

I couldn't agree more. Not to mention that they are probably slower.

PS Don't get me wrong I like perl and pcre but it is pointless here.




Personal choice, and yes my testing has proven that a regex is faster then the 
multiple function calls or if conditions needed to accomplish the same
thing.

  


I think that no one will argue that (I like perl and its power to make 
regular expressions easy to use) but if you make the same thing with a 
simple function I think that is useless to call pcre because that adds 
some load to the script.


No much difference but you still have to think how to add the expression 
and check if it matches the right data...


--
Thodoris



[PHP] PHP and Cyrus problem

2008-11-06 Thread Emerson Virti
Hello,
My company have almost ten thousand mailboxes on Cyrus Imap.
We use Thunderbird for IMAP client and PHP for webmail.
We have a problem in a very few mailboxes. This boxes don't have any visible
problem with Thunderbird access but in PHP, the (webmail) access provide a
"segmentation failed".
If I modify the cyrus.header file the "segmentation failed" problem is
resolved.

This is a problematic cyrus.header:
¡^B<8b>^MCyrus mailbox header
"The best thing about this system was that it had lots of goals."
--Jim Morris on Andrew
user.02401695bc4b7c0488731c8
0240169 lrswipcda$Forwarded $label1 $label4 $label2 $label3
$label5 $MDNSent NonJunk acade acgap alfredo andre_porto carneiro chevalier
cida-bruno cida_coutinho claudia concei&aoca4w-o daniela elaine erlan
fazer_reuni&aom-o fernanda godinho helenac inah joao_almeida katia lm luis
mara marcio_rfb marco maria_lucia_-_acbsa nelicio pc pendente plinio pp
resolvido rwagner tema vinicius-oracle
0240169 lrswipcda

If I modify cyrus.header, the "segmentation failed" is resolved, but this
generate a Thunderbird labels messages problem.

Modified cyrus.header:
¡^B<8b>^MCyrus mailbox header
"The best thing about this system was that it had lots of goals."
--Jim Morris on Andrew
user.02401695bc4b7c0488731c8
0240169 lrswipcda$Forwarded $label1 $label4 $label2 $label3
$label5 $MDNSent NonJunk
0240169 lrswipcda

Thunderbird version: 2.0.0.14;
PHP version (Debian Etch): 5.2.0-8+etch7
Cyrus Impad version: cyrus-imapd-2.2.12-8.1.RHEL4

I use this simple php script for tests:

If the cyrus.header file is the problematic one, the result of this script
is a list os subfolders and a "segmentation failed".

Where is the problem?

Thanks.

-- 
Émerson Salvadori Virti
[EMAIL PROTECTED]


Re: [PHP] basic php question... [compliance]

2008-11-06 Thread Thodoris



At 6:53 PM +0200 11/5/08, Thodoris wrote:

Thank you oh mighty and good God that I don't live in America!!

How do you manage all these strange things you guys ?


Nothing strange about it -- it's just the evolution of technology.



Evolution?? Really ? Disabling js?


Things are improving for everyone. Certainly that does not mean it 
will be absent of growing pains, but today is better than it was 
yesterday. If nothing else, IE6 is less popular than it was.


Cheers,

tedd



I think I will go back to my cave and stay with my laptop until this 
heretic revolution comes to an end.


PS I promise I will only use lamp and WiFi

--
Thodoris


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



Re: [PHP] Random number generator

2008-11-06 Thread tedd

At 11:35 AM -0600 11/6/08, WEISD wrote:

http://www.weisd.com/store2/WINHD-9022.php



Not me -- I get a normal distribution.

Cheers,

tedd



Thanks Tedd,  That is because it is using  time now and not rand...



Just as point of notice.

When I ask a question and provide a url, I keep the url there "as-is" 
until the question is answered -- at which time I remove the example. 
If the url is not there, then people can assume that the problem is 
solved. This allows people to see the problem and prevents wasting 
time.


Cheers,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



[PHP] Printing Web Page

2008-11-06 Thread Patrick Moloney
I'd like to enable my users to print individual web pages from their 
browser. If they simply select the browser print button they don't get 
all the text that is displayed in a scrolling text area.

The web page is static html and css, in a php file.

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



[PHP] Infinite Loop Issue

2008-11-06 Thread Kyle Terry
I believe I'm doing everything right here. It just seems like it doesn't
end. The browser just keeps trying to load the page forever...

function displayAll(){
global $db;
$sql = "SELECT release_id, description, date(release_date) date, issues,
priority FROM release_data";
$all = $db->prepare($sql);
$all->execute();
$all->bind_result($release_id, $description, $date, $issues, $priority);

while($all->fetch()){

$i = 0;
$iss_link = explode(', ', $issues);
foreach($iss_link as $a){
  $row2[$i] = "http://mantisus/view.php?id=$a\";
target=\"_blank\">".$a.'';
  $i++;
}
$issues = implode(', ', $row2);

echo $release_id;
echo $description;
echo $date;
echo $issues;
echo $priority;
echo '';
}

$all->close();
}

-- 
Kyle Terry | www.kyleterry.com


Re: [PHP] removing text from a string

2008-11-06 Thread Stut

On 6 Nov 2008, at 18:33, Thodoris wrote:

This :

ltrim($line, '0123456789 .');


does remove all those characters doesn't it (as the OP asked and  
Richard suggested on a previous thread). Without calling it more  
than once as far as I tested. That was my point on the first place  
and sorry if I didn't make that clear. On the other hand who ever  
suggested calling ltrim without the second parameter.


You suggested before something like that:

ltrim(ltrim(ltrim($line, '0123456789'), '.'))


when you made a comparison didn't you?

Sorry if I got that wrong I meant no offense and I still don't.


That doesn't meet the objectives. Consider that $line might be "1. 100  
apples". Your solution has reduced it to "apples" rather than the  
required "100 apples".


Calling it three times as was suggested will produce the correct result.

-Stut

--
http://stut.net/

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



RE: [PHP] Printing Web Page

2008-11-06 Thread Jay Blanchard
[snip]
I'd like to enable my users to print individual web pages from their 
browser. If they simply select the browser print button they don't get 
all the text that is displayed in a scrolling text area.
The web page is static html and css, in a php file.
[/snip]

There are some very good articles on setting up a CSS for printing web
pages if you search Google.

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



Re: [PHP] removing text from a string

2008-11-06 Thread Jim Lucas
Thodoris wrote:
> 
>> Thodoris wrote:
>>  
 Thodoris wrote:
  
  
>> Boyd, Todd M. wrote:
>>  
>>   
 -Original Message-
 From: Ashley Sheridan [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, November 04, 2008 1:40 PM
 To: Adam Williams
 Cc: PHP General list
 Subject: Re: [PHP] removing text from a string

 On Tue, 2008-11-04 at 08:04 -0600, Adam Williams wrote:

> I have a file that looks like:
>
> 1. Some Text here
> 2. Another Line of Text
> 3. Yet another line of text
> 340. All the way to number 340
>
> And I want to remove the Number, period, and blank space at the
> 
 begining

> of each line.  How can I accomplish this?
>
> Opening the file to modify it is easy, I'm just lost at how to
> 
>>> remove
>>>  
> the text.:
>
>  $filename = "results.txt";
>
> $fp = fopen($filename, "r") or die ("Couldn't open $filename");
> if ($fp)
> {
> while (!feof($fp))
> {
> $thedata = fgets($fp);
> //Do something to remove the "1. "
> //print the modified line and \n
> }
> fclose($fp);
> }
> ?>
>
> 
 I'd go with a regular expression any day for something like this.
 Something like:

 "/$[0-9]{1,3}\.\ .*^/g"

 should do what you need. Note the space before the last period.
   
>>> That would only work for files with 1-999 lines, and will wind up
>>> matching the entire line (since you used $ and ^ and a greedy .*
>>> inbetween... also... $ is "end-of-line" and ^ is
>>> "beginning-of-line" :))
>>> rather than just the "line number" part. I would stick with my
>>> originally-posted regex ("/^\d+\.\s/"), but I would modify yours
>>> like
>>> this if I were to use it instead:
>>>
>>> "/^[0-9]+\.\ (.*)$/" (What was the "g" modifier for, anyway?)
>>>
>>> Then, you could grab the capture group made with (.*) and use it as
>>> the
>>> "clean" data. (It would be group 1 in the match results and "$1"
>>> in a
>>> preg_replace() call, I believe. Group 0 should be the entire match.)
>>>
>>>
>>> Todd Boyd
>>> Web Programmer
>>>
>>> 
>> Personally, I would go this route if you wanted to stick with a
>> regex.
>>
>> >
>> $lines[] = '01. asdf';
>> $lines[] = '02. 323 asdf';
>> $lines[] = '03.2323 asdf';
>> $lines[] = '04. asdf 23';
>> $lines[] = '05.asdf'; /* tabs used here */
>> $lines[] = '06. asdf';
>>
>> foreach ( $lines AS $line ) {
>> echo preg_replace('/^[0-9]+\.\s*/', '', $line), "\n";
>> }
>>
>> ?>
>>
>> This takes care of all possible issues related to the char after the
>> first period.  Maybe it is there maybe not.
>>
>> Could be that it is a tab and not a space.  Could even be multiple
>> tabs or spaces.
>>
>>   
> There it goes again.
>
> Every time someone asks a simple question (like the kind it's solved
> with a simple trim, ltrim or rtrim) the discussion about which is the
> best regular expression for this problem, makes a thread get
> "elephant"
> sized :-) .
>
> I love this list!!
>
> 
 Your not going to be able to get it with any of the xtrim()
 functions.  you would end up with various nested ltrim() calls that,
 IMO, would be a
 nightmare to manage.

 So, a top to bottom comparison here

 If $line is this:
 $line = '01. asdf';

 And you use either one of these:
 A) ltrim(ltrim(ltrim($line, '0123456789'), '.'));
 B) preg_replace('/^[0-9]+\.\s*/', '', $line);

 Which do you prefer?

 A's Pros:
 Not a regex
 A's Cons:
 A little slower then B
 multiple function calls

 B's Pros:
 Slightly faster then A
 Single Function call
 B's Cons:
 Regex



 
>>> You should really check the manual again Jim. AFAIK ltrim doesn't remove
>>> a single character but as long they belong to the list they are all
>>> removed you just do:
>>>
>>> ltrim($line, '0123456789')
>>>
>>>
>>> and this does the job perfectly. So perhaps you need to reconsider your
>>> thoughts on this.
>>>
>>> 
>>
>> Maybe instead of saying "AFAIK", you should go and check it yourself. 
>> But obviously, since you didn't ca

Re: [PHP] Infinite Loop Issue

2008-11-06 Thread Nathan Nobbe
On Thu, Nov 6, 2008 at 1:34 PM, Kyle Terry <[EMAIL PROTECTED]> wrote:

> I believe I'm doing everything right here. It just seems like it doesn't
> end. The browser just keeps trying to load the page forever...
>
> function displayAll(){
>global $db;
>$sql = "SELECT release_id, description, date(release_date) date, issues,
> priority FROM release_data";
>$all = $db->prepare($sql);
>$all->execute();
>$all->bind_result($release_id, $description, $date, $issues, $priority);
>
>while($all->fetch()){
>
>$i = 0;
>$iss_link = explode(', ', $issues);
>foreach($iss_link as $a){
>  $row2[$i] = " href=\"http://mantisus/view.php?id=$a\
> "
> target=\"_blank\">".$a.'';
>  $i++;
>}
>$issues = implode(', ', $row2);
>
>echo $release_id;
>echo $description;
>echo $date;
>echo $issues;
>echo $priority;
>echo '';
>}
>
>$all->close();
> }


w/e $all is, im guessing $all->fetch() is never returning false (or a value
which can be type juggled to a boolean false equiv).  if youre code is
getting beyond the while loop, then there could be something wrong w/
$all->close(); and if its getting passed that, then obviously, something
else is wrong.

-nathan


Re: [PHP] Printing Web Page

2008-11-06 Thread Frank Arensmeier

6 nov 2008 kl. 21.21 skrev Patrick Moloney:

I'd like to enable my users to print individual web pages from their  
browser. If they simply select the browser print button they don't  
get all the text that is displayed in a scrolling text area.

The web page is static html and css, in a php file.



This might be a good starting point.

http://www.alistapart.com/articles/printyourway

//frank


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



Re: [PHP] Infinite Loop Issue

2008-11-06 Thread Chris

Kyle Terry wrote:

I believe I'm doing everything right here. It just seems like it doesn't
end. The browser just keeps trying to load the page forever...

function displayAll(){
global $db;
$sql = "SELECT release_id, description, date(release_date) date, issues,
priority FROM release_data";
$all = $db->prepare($sql);
$all->execute();
$all->bind_result($release_id, $description, $date, $issues, $priority);

while($all->fetch()){

$i = 0;
$iss_link = explode(', ', $issues);
foreach($iss_link as $a){
  $row2[$i] = "http://mantisus/view.php?id=$a\";
target=\"_blank\">".$a.'';
  $i++;
}


In pseudo code you have:

for each result from the db
explode the issues
add another issue to the list

So:
no issues at start

row 1 fetched
explodes issues
adds another issue (1 issue)

row 2 fetched
explodes issues (now 1)
add another issue (now 2)

row 3 fetch
explode issues (now 2)
add another issue (now 3)

and so on.

So your list is getting longer and longer and you're adding to it for 
each row you get from the db.


--
Postgresql & php tutorials
http://www.designmagick.com/


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



Re: [PHP] Infinite Loop Issue

2008-11-06 Thread Daniel Brown
On Thu, Nov 6, 2008 at 4:34 PM, Nathan Nobbe <[EMAIL PROTECTED]> wrote:
>
> w/e $all is, im guessing $all->fetch() is never returning false (or a value
> which can be type juggled to a boolean false equiv).  if youre code is
> getting beyond the while loop, then there could be something wrong w/
> $all->close(); and if its getting passed that, then obviously, something
> else is wrong.

Right.  It may also be worth asking exactly how the OP determined
that it's the particular function he showed.

Kyle, are you positive that your displayAll() function is even the
point of fault?

-- 

http://www.parasane.net/
[EMAIL PROTECTED] || [EMAIL PROTECTED]
Ask me about our current hosting/dedicated server deals!

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



[PHP] I have a problem with dynamicly updating files...

2008-11-06 Thread satinder singh
I got a lot through a tutorial, but problem is when i tried to insert,
problem occured using following code:

$query = "INSERT INTO contacts VALUES
('','$first','$last','$phone','$mobile','$fax','$email','$web')";
mysql_query($query);

But when i used a code provided by my server for same purpose was
sucessful, which was:

$sql = 'INSERT INTO `server account_database name`.`table name` (`id`,
`first`, `description`, `mobile`, `fax`, `email`, `web`) VALUES (NULL,
\'first\', \'$description\', \'$mobile\', \'$fax\', \'ghjhjhg\',
\'ghgjghjghkgk\');';

Now My problem is that :-
  It supports only a single or static  record at a time & from my
cpanel, but I want that the users of my website can
fill that form and when the click "submit query", then their input
should be added to the table and they can view their data...

I think that , here is a trouble in diff. version. Please If you give
me the code(query").
With this hope that you will surely reply me at [EMAIL PROTECTED]

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



Re: [PHP] Infinite Loop Issue

2008-11-06 Thread Kyle Terry
Positive,

It's the only function being called in the test script.

On Thu, Nov 6, 2008 at 1:40 PM, Daniel Brown <[EMAIL PROTECTED]> wrote:

> On Thu, Nov 6, 2008 at 4:34 PM, Nathan Nobbe <[EMAIL PROTECTED]>
> wrote:
> >
> > w/e $all is, im guessing $all->fetch() is never returning false (or a
> value
> > which can be type juggled to a boolean false equiv).  if youre code is
> > getting beyond the while loop, then there could be something wrong w/
> > $all->close(); and if its getting passed that, then obviously, something
> > else is wrong.
>
> Right.  It may also be worth asking exactly how the OP determined
> that it's the particular function he showed.
>
>Kyle, are you positive that your displayAll() function is even the
> point of fault?
>
> --
> 
> http://www.parasane.net/
> [EMAIL PROTECTED] || [EMAIL PROTECTED]
> Ask me about our current hosting/dedicated server deals!
>



-- 
Kyle Terry | www.kyleterry.com


Re: [PHP] Infinite Loop Issue

2008-11-06 Thread Nathan Nobbe
On Thu, Nov 6, 2008 at 2:49 PM, Kyle Terry <[EMAIL PROTECTED]> wrote:

> Positive,
>
> It's the only function being called in the test script.


so is the code making it past the while w/ the $all->fetch() condition ?  it
might be helpful to comment-out the body of said while loop and see if
script execution makes it past the while.  if not, there is def something
wrong w/ $all->fetch().

-nathan


Re: [PHP] basic php question...

2008-11-06 Thread Ashley Sheridan
On Thu, 2008-11-06 at 14:28 +0200, Thodoris wrote:
> 
> 
> > On Wed, 2008-11-05 at 18:48 +0200, Thodoris wrote:
> >   
> > > > Richard Heyes a écrit :
> > > >   
> > > > > > users who browse without Javascript enabled,
> > > > > >   
> > > > > Heretics!
> > > > > 
> > > > > 
> > > > No, paranoid :D
> > > > 
> > > >   
> > > Do these people really exist? I though that their extinction happened 
> > > the same with the dinosaurs.
> > > 
> > > -- 
> > > Thodoris
> > > 
> > > 
> > > 
> > Lots of reasons:
> > 
> > * some proxy servers (e.g. at work) strip out some scripts
> >   
> 
> Those evil netadmins should be blamed for this!!
> > * some mobile/text browsers don't have that option
> >   
> 
> Does anybody is really browsing from that kind of a phone ? Truly
> heretic!!
> > * some people do _really_ browse with it turned off!
> >   
> 
> Should be banished to outer space (links and lynx users are excluded).
> > 
> > Ash
> > www.ashleysheridan.co.uk
> > 
> >   
> 
> I think that I just got through a cultural shock :-) .
> -- 
> Thodoris
I browse on my phone with an older version of Opera, which doesn't
support much (if any?) Javascript, and I do turn it off in normal
browsers to see how things work, although mostly this is with my own
stuff, so I can make sure it is good in terms of SEO and accessibility.


Ash
www.ashleysheridan.co.uk


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



Re: [PHP] Printing Web Page

2008-11-06 Thread Ashley Sheridan
On Thu, 2008-11-06 at 22:35 +0100, Frank Arensmeier wrote:
> 6 nov 2008 kl. 21.21 skrev Patrick Moloney:
> 
> > I'd like to enable my users to print individual web pages from their  
> > browser. If they simply select the browser print button they don't  
> > get all the text that is displayed in a scrolling text area.
> > The web page is static html and css, in a php file.
> >
> 
> This might be a good starting point.
> 
> http://www.alistapart.com/articles/printyourway
> 
> //frank
> 
> 


Then set out your CSS in print.css to lay out the page without scrolling
areas.


Ash
www.ashleysheridan.co.uk


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



Re: [PHP] I have a problem with dynamicly updating files...

2008-11-06 Thread Wolf
 satinder singh <[EMAIL PROTECTED]> wrote: 
> I got a lot through a tutorial, but problem is when i tried to insert,
> problem occured using following code:
> 
> $query = "INSERT INTO contacts VALUES
> ('','$first','$last','$phone','$mobile','$fax','$email','$web')";
> mysql_query($query);



Your query looks fine.  You need to look at the error codes you receive.

change:
mysql_query($query); 
TO: 
mysql_query($query) or die(mysql_error());

The resulting error message should help you find your MySQL issue.

Wolf

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



Re: [PHP] I have a problem with dynamicly updating files...

2008-11-06 Thread Ashley Sheridan
On Fri, 2008-11-07 at 03:18 +0530, satinder singh wrote:
> I got a lot through a tutorial, but problem is when i tried to insert,
> problem occured using following code:
> 
> $query = "INSERT INTO contacts VALUES
> ('','$first','$last','$phone','$mobile','$fax','$email','$web')";
> mysql_query($query);
> 
> But when i used a code provided by my server for same purpose was
> sucessful, which was:
> 
> $sql = 'INSERT INTO `server account_database name`.`table name` (`id`,
> `first`, `description`, `mobile`, `fax`, `email`, `web`) VALUES (NULL,
> \'first\', \'$description\', \'$mobile\', \'$fax\', \'ghjhjhg\',
> \'ghgjghjghkgk\');';
> 
> Now My problem is that :-
>   It supports only a single or static  record at a time & from my
> cpanel, but I want that the users of my website can
> fill that form and when the click "submit query", then their input
> should be added to the table and they can view their data...
> 
> I think that , here is a trouble in diff. version. Please If you give
> me the code(query").
> With this hope that you will surely reply me at [EMAIL PROTECTED]
> 
You can only omit the fields you are adding data to in an INSERT query
if you are inserting data into ALL the fields, and in the order they
occur in the table.

However, I'm not sure quite what your problem is, could you give some
more details?


Ash
www.ashleysheridan.co.uk


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



Re: [PHP] Infinite Loop Issue

2008-11-06 Thread Nathan Nobbe
On Thu, Nov 6, 2008 at 3:01 PM, Kyle Terry <[EMAIL PROTECTED]> wrote:

> looks like its $all->fetch();
>
> The query runs fine in MySQL...


please keep responses on-list for the benefit of others.

what type of class is $all an instance of, and what causes the fetch()
function to return false (or something that php can juggle to an equivalent,
such as 0).

-nathan


Re: [PHP] Infinite Loop Issue

2008-11-06 Thread Kyle Terry
On Thu, Nov 6, 2008 at 2:47 PM, Nathan Nobbe <[EMAIL PROTECTED]> wrote:

> On Thu, Nov 6, 2008 at 3:01 PM, Kyle Terry <[EMAIL PROTECTED]> wrote:
>
>> looks like its $all->fetch();
>>
>> The query runs fine in MySQL...
>
>
> please keep responses on-list for the benefit of others.
>
> what type of class is $all an instance of, and what causes the fetch()
> function to return false (or something that php can juggle to an equivalent,
> such as 0).
>
> -nathan
>
>
Sorry, I was actually having a conversation about that with Daniel. It is an
instance of the mysqli class.


Re: [PHP] Infinite Loop Issue

2008-11-06 Thread Daniel P. Brown
On Thu, Nov 6, 2008 at 5:51 PM, Kyle Terry <[EMAIL PROTECTED]> wrote:
>>
> Sorry, I was actually having a conversation about that with Daniel. It is an
> instance of the mysqli class.

Yeah, Nathan, keep it down while the grown-ups are talking.

-- 

http://www.parasane.net/
[EMAIL PROTECTED] || [EMAIL PROTECTED]
Ask me about our current hosting/dedicated server deals!

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



Re: [PHP] Infinite Loop Issue

2008-11-06 Thread Chris

Kyle Terry wrote:

I believe I'm doing everything right here. It just seems like it doesn't
end. The browser just keeps trying to load the page forever...

function displayAll(){
global $db;
$sql = "SELECT release_id, description, date(release_date) date, issues,
priority FROM release_data";


how many rows does this return?



while($all->fetch()){

$i = 0;
$iss_link = explode(', ', $issues);
foreach($iss_link as $a){
  $row2[$i] = "http://mantisus/view.php?id=$a\";
target=\"_blank\">".$a.'';
  $i++;
}




You have a loop inside a loop. What makes it worse is that the loop is 
growing with every iteration.


If there are 100 rows, then at the end, there are 100 entries in the 
$issues array.


To get to that point, you are doing a loop of size "X" where "X" = the 
row number being processed. ie row "2" is doing a foreach over 2 
entries. row 15 is doing a foreach over 15 entries. row 90 is doing a 
foreach over 90 entries.



--
Postgresql & php tutorials
http://www.designmagick.com/


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



Re: [PHP] Infinite Loop Issue

2008-11-06 Thread Nathan Nobbe
On Thu, Nov 6, 2008 at 3:54 PM, Daniel P. Brown
<[EMAIL PROTECTED]>wrote:

> On Thu, Nov 6, 2008 at 5:51 PM, Kyle Terry <[EMAIL PROTECTED]> wrote:
> >>
> > Sorry, I was actually having a conversation about that with Daniel. It is
> an
> > instance of the mysqli class.
>
> Yeah, Nathan, keep it down while the grown-ups are talking.


force of habit from a careless 'young' adult like me ;)

-nathan


Re[2]: [PHP] Invalid byte sequence for encoding UTF-8

2008-11-06 Thread ANR Daemon
Greetings, paragasu.
In reply to Your message dated Friday, October 31, 2008, 12:39:14,

>>> i am using php with postgresql. when i submit post query to the
>>> server. i have the pg_exec error
>>> 
>>> Warning: pg_query() [function.pg-query]: Query failed: ERROR: invalid
>>> byte sequence for encoding "UTF8": 0x93 HINT: This error can also
>>> happen if the byte sequence does not match the encoding expected by
>>> the server, which is controlled by "client_encoding".
>>> 
>>> is there any function to prevent this type of error. something i can
>>> apply to any POST query
>>> before i submit to pg_query() ?
>>
>> You probably need to tell us which functions you are using to create/modify
>> the UTF8 string that you are sending as data. I does sound like a conversion
>> TO UTF8 is not being carried out somewhere. PHP5 requires that only
>> multi-byte
>> string functions are used to handle UTF8 data
>>
> i do not use any function other that addslashes on the $_POST

Here is what you're doing wrong.
I'm 99% sure you have applied it in wrong place and have your data sent out
already destroyed by addslashes.

Only 2 places where any escaping should occur:
1. before writing data to storage, use appropriate storage-dependent escaping
routine.
2. before sending data to client. Use appropriate encoding routine, such as
htmlentites()

Don't use add*slashes and any kind of it, including magic_quotes*, unless you
surely know what you're doing and why. 

And please, don't top-post.


-- 
Sincerely Yours, ANR Daemon <[EMAIL PROTECTED]>


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



Re: [PHP] Infinite Loop Issue

2008-11-06 Thread Andrew Ballard
On Thu, Nov 6, 2008 at 5:56 PM, Chris <[EMAIL PROTECTED]> wrote:
> Kyle Terry wrote:
>>
>> I believe I'm doing everything right here. It just seems like it doesn't
>> end. The browser just keeps trying to load the page forever...
>>
>> function displayAll(){
>>global $db;
>>$sql = "SELECT release_id, description, date(release_date) date,
>> issues,
>> priority FROM release_data";
>
> how many rows does this return?
>
>
>>while($all->fetch()){
>>
>>$i = 0;
>>$iss_link = explode(', ', $issues);
>>foreach($iss_link as $a){
>>  $row2[$i] = "http://mantisus/view.php?id=$a\";
>> target=\"_blank\">".$a.'';
>>  $i++;
>>}
>
> 
>
> You have a loop inside a loop. What makes it worse is that the loop is
> growing with every iteration.
>
> If there are 100 rows, then at the end, there are 100 entries in the $issues
> array.
>
> To get to that point, you are doing a loop of size "X" where "X" = the row
> number being processed. ie row "2" is doing a foreach over 2 entries. row 15
> is doing a foreach over 15 entries. row 90 is doing a foreach over 90
> entries.

That's not QUITE right. The value of $issues will always be set to the
column value for the next row when $all->fetch() is called, therefore
overwriting the value it had after the previous iteration. The
variable $row2 should be set to an empty array before the foreach loop
just in case different rows have different numbers of issues.

Iteration 1:
before foreach
$issues == 'a, b, c'
$i == 0
$iss_link == Array
(
[0] => 'a',
[1] => 'b',
[2] => 'c'
)
$row2 == empty

after foreach
$i == 2
$row2 == Array
(
[0] => 'http://mantisus/view.php?id=a"; target="_blank">a',
[1] => 'http://mantisus/view.php?id=b"; target="_blank">b',
[2] => 'http://mantisus/view.php?id=c"; target="_blank">c',
)

after implode
$issues == 'http://mantisus/view.php?id=a";
target="_blank">a, http://mantisus/view.php?id=b";
target="_blank">b, http://mantisus/view.php?id=c";
target="_blank">c'

Iteration 2:
before foreach:
$issues == '1, 2'
$i == 0
$iss_link == Array
(
[0] => '1',
[1] => '2',
)
/* STILL CONTAINS THE ARRAY FROM THE PREVIOUS ITERATION */
$row2 == Array
(
[0] => 'http://mantisus/view.php?id=a"; target="_blank">a',
[1] => 'http://mantisus/view.php?id=b"; target="_blank">b',
[2] => 'http://mantisus/view.php?id=c"; target="_blank">c',
)


after foreach:
$i == 1
$row2 == Array
(
[0] => 'http://mantisus/view.php?id=1"; target="_blank">1',
[1] => 'http://mantisus/view.php?id=2"; target="_blank">2',
[2] => 'http://mantisus/view.php?id=c"; target="_blank">c',
)


after implode:
$issues == 'http://mantisus/view.php?id=1";
target="_blank">1, http://mantisus/view.php?id=2";
target="_blank">2, http://mantisus/view.php?id=c";
target="_blank">c'


There is the potential for wrong behavior, but it the multiplicative
loops you are talking about shouldn't happen.

Andrew

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



Re: [PHP] Infinite Loop Issue

2008-11-06 Thread Eric Butera
On Thu, Nov 6, 2008 at 5:57 PM, Nathan Nobbe <[EMAIL PROTECTED]> wrote:
> On Thu, Nov 6, 2008 at 3:54 PM, Daniel P. Brown
> <[EMAIL PROTECTED]>wrote:
>
>> On Thu, Nov 6, 2008 at 5:51 PM, Kyle Terry <[EMAIL PROTECTED]> wrote:
>> >>
>> > Sorry, I was actually having a conversation about that with Daniel. It is
>> an
>> > instance of the mysqli class.
>>
>> Yeah, Nathan, keep it down while the grown-ups are talking.
>
>
> force of habit from a careless 'young' adult like me ;)
>
> -nathan
>

I was kinda thinking trying put a limit 1 on that sql statement might
be a worthwhile test too.  Hard to really say without actually since
I've never used this particular ext.

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



Re: [PHP] Infinite Loop Issue

2008-11-06 Thread Chris



To get to that point, you are doing a loop of size "X" where "X" = the row
number being processed. ie row "2" is doing a foreach over 2 entries. row 15
is doing a foreach over 15 entries. row 90 is doing a foreach over 90
entries.


That's not QUITE right. The value of $issues will always be set to the
column value for the next row when $all->fetch() is called, therefore
overwriting the value it had after the previous iteration. The
variable $row2 should be set to an empty array before the foreach loop
just in case different rows have different numbers of issues.


You're right, I missed that $issues was a bind_result.

--
Postgresql & php tutorials
http://www.designmagick.com/


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



Re: [PHP] Infinite Loop Issue

2008-11-06 Thread Jim Lucas
Kyle Terry wrote:
> I believe I'm doing everything right here. It just seems like it doesn't
> end. The browser just keeps trying to load the page forever...
> 
> function displayAll(){
> global $db;

What the heck is in $db?  Which SQL class(es) are you using for your DB handler?

> $sql = "SELECT release_id, description, date(release_date) date, issues,
> priority FROM release_data";
> $all = $db->prepare($sql);
> $all->execute();
> $all->bind_result($release_id, $description, $date, $issues, $priority);

Not sure, but is your bind_results() method handling all the variable here as 
pass by reference?

If so, I hope you are not expecting them to be updated as you run the while 
loop below...

> 
> while($all->fetch()){

Usually, a while statement like this looks a little more like this...

while( $row = $all->fetch() ) {

> 
> $i = 0;
> $iss_link = explode(', ', $issues);

Where are you defining the $issues variable?  Where is this coming from?

I see that it will exist on the second pass through, but you need to not cause 
a PHP E_NOTICE warning...

> foreach($iss_link as $a){
>   $row2[$i] = "http://mantisus/view.php?id=$a\";
> target=\"_blank\">".$a.'';
>   $i++;

Why have a counter here???  php will take care of dynamically added an index to 
an array if you call it with $row2[]

> }
> $issues = implode(', ', $row2);
> 
> echo $release_id;
> echo $description;
> echo $date;
> echo $issues;
> echo $priority;
> echo '';

Where are the above variables defined/create?

> }
> 
> $all->close();
> }
> 


-- 
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare


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



[PHP] Re: Infinite Loop Issue

2008-11-06 Thread Lupus Michaelis

Kyle Terry a écrit :

I believe I'm doing everything right here. It just seems like it doesn't
end. The browser just keeps trying to load the page forever...


  If the problem doesn't seem to be there, you could see the wrong code 
snipset :D


  Did check out your error log from PHP, from Apache ? ? Some time, the 
segfault of Apache (due to self or PHP) cause the same effect than an 
infinite loop.


--
Mickaël Wolff aka Lupus Michaelis
http://lupusmic.org

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