php-general Digest 7 Nov 2008 09:47:55 -0000 Issue 5777

Topics (messages 283023 through 283049):

Infinite Loop Issue
        283023 by: Kyle Terry
        283027 by: Nathan Nobbe
        283029 by: Chris
        283030 by: Daniel Brown
        283032 by: Kyle Terry
        283033 by: Nathan Nobbe
        283038 by: Nathan Nobbe
        283039 by: Kyle Terry
        283040 by: Daniel P. Brown
        283041 by: Chris
        283042 by: Nathan Nobbe
        283044 by: Andrew Ballard
        283045 by: Eric Butera
        283046 by: Chris
        283047 by: Jim Lucas
        283048 by: Lupus Michaelis

Re: removing text from a string
        283024 by: Stut
        283026 by: Jim Lucas

Re: Printing Web Page
        283025 by: Jay Blanchard
        283028 by: Frank Arensmeier
        283035 by: Ashley Sheridan

I have a problem with dynamicly updating files...
        283031 by: satinder singh
        283036 by: Wolf
        283037 by: Ashley Sheridan

Re: basic php question...
        283034 by: Ashley Sheridan

Re: Invalid byte sequence for encoding UTF-8
        283043 by: ANR Daemon

Re: PHP and Cyrus problem
        283049 by: Colin Guthrie

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
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] = "<a href=\"http://mantisus/view.php?id=$a\";
target=\"_blank\">".$a.'</a>';
          $i++;
        }
        $issues = implode(', ', $row2);

        echo $release_id;
        echo $description;
        echo $date;
        echo $issues;
        echo $priority;
        echo '<br />';
    }

    $all->close();
}

-- 
Kyle Terry | www.kyleterry.com

--- End Message ---
--- Begin Message ---
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] = "<a 
> href=\"http://mantisus/view.php?id=$a\<http://mantisus/view.php?id=$a%5C>
> "
> target=\"_blank\">".$a.'</a>';
>          $i++;
>        }
>        $issues = implode(', ', $row2);
>
>        echo $release_id;
>        echo $description;
>        echo $date;
>        echo $issues;
>        echo $priority;
>        echo '<br />';
>    }
>
>    $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

--- End Message ---
--- Begin Message ---
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] = "<a href=\"http://mantisus/view.php?id=$a\";
target=\"_blank\">".$a.'</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/


--- End Message ---
--- Begin Message ---
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?

-- 
</Daniel P. Brown>
http://www.parasane.net/
[EMAIL PROTECTED] || [EMAIL PROTECTED]
Ask me about our current hosting/dedicated server deals!

--- End Message ---
--- Begin Message ---
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?
>
> --
> </Daniel P. Brown>
> http://www.parasane.net/
> [EMAIL PROTECTED] || [EMAIL PROTECTED]
> Ask me about our current hosting/dedicated server deals!
>



-- 
Kyle Terry | www.kyleterry.com

--- End Message ---
--- Begin Message ---
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

--- End Message ---
--- Begin Message ---
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

--- End Message ---
--- Begin Message ---
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.

--- End Message ---
--- Begin Message ---
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.

-- 
</Daniel P. Brown>
http://www.parasane.net/
[EMAIL PROTECTED] || [EMAIL PROTECTED]
Ask me about our current hosting/dedicated server deals!

--- End Message ---
--- Begin Message ---
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] = "<a href=\"http://mantisus/view.php?id=$a\";
target=\"_blank\">".$a.'</a>';
          $i++;
        }

<snip>

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/


--- End Message ---
--- Begin Message ---
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

--- End Message ---
--- Begin Message ---
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] = "<a href=\"http://mantisus/view.php?id=$a\";
>> target=\"_blank\">".$a.'</a>';
>>          $i++;
>>        }
>
> <snip>
>
> 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] => '<a href="http://mantisus/view.php?id=a"; target="_blank">a</a>',
    [1] => '<a href="http://mantisus/view.php?id=b"; target="_blank">b</a>',
    [2] => '<a href="http://mantisus/view.php?id=c"; target="_blank">c</a>',
)

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

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] => '<a href="http://mantisus/view.php?id=a"; target="_blank">a</a>',
    [1] => '<a href="http://mantisus/view.php?id=b"; target="_blank">b</a>',
    [2] => '<a href="http://mantisus/view.php?id=c"; target="_blank">c</a>',
)


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


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


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

Andrew

--- End Message ---
--- Begin Message ---
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.

--- End Message ---
--- Begin Message ---

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/


--- End Message ---
--- Begin Message ---
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] = "<a href=\"http://mantisus/view.php?id=$a\";
> target=\"_blank\">".$a.'</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 '<br />';

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


--- End Message ---
--- Begin Message ---
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

--- End Message ---
--- Begin Message ---
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/

--- End Message ---
--- Begin Message ---
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.:
>>>>>>>>>
>>>>>>>>> <?php
>>>>>>>>> $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.
>>>>>>
>>>>>> <?php
>>>>>>
>>>>>> $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)), 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 .');
> 

The reason that this doesn't (maybe) work is because of the situations that 
were pointed out earlier in this thread.

The following will show you why your example above will not work in all cases

$str = '01. asdf';              Yes
$str = '02.2323 asdf';          No
$str = '03. 2323 asdf';         No
$str = '04.        asdf';       No /* tabs used here */

Success only 25% of the time is not good enough for me, nor should it be for 
you.

But, if you were to use the regex version I described, it would work for all 
above examples.

As for calling ltrim() without the second param, let me explain a little more...

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

extracted looks like the following

$line = ltrim($line, '0123456789');   Removes all leading numbers, if present
$line = ltrim($line, '.');            Removes all leading periods, if present 
(small problem described below)
$line = ltrim($line);                 Removes all leading white space, if 
present (spaces, tabs, etc...)

There is still one problem with the above method.

What if you come across this.  $str = '04....etc'; or $str = '04.... etc';

if the intended results for both of the last examples is just 'etc', then it 
will work.

But what if it is '... etc' or '...etc', in this case, neither my regex or the 
ltrim()'s will catch it.

So, in this case, you cannot program for 100% accuracy, but the closer to 100% 
I can get the better the customer will feel.

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


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


--- End Message ---
--- Begin Message ---
[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.

--- End Message ---
--- Begin Message ---
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


--- End Message ---
--- Begin Message ---
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
> 
> 
<link href="print.css" media="print" type="text/css" rel="stylesheet"/>

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


Ash
www.ashleysheridan.co.uk


--- End Message ---
--- Begin Message ---
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]

--- End Message ---
--- Begin Message ---
---- 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);

<!-- SNIP -->

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

--- End Message ---
--- Begin Message ---
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


--- End Message ---
--- Begin Message ---
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


--- End Message ---
--- Begin Message ---
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
>>> <snip>
>>> 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".
>>> </snip>
>>> 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]>


--- End Message ---
--- Begin Message ---
Emerson Virti wrote:
Where is the problem?

Probably not the right list, but have you tried using cyradm and running: reconstruct user.name.mailbox.name

(correct the folder as needed).

When a cyrus database file gets corrupted or generally borked this fixes it 99% of the time for me.

Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


--- End Message ---

Reply via email to