php-general Digest 4 Sep 2009 20:12:09 -0000 Issue 6322

Topics (messages 297663 through 297689):

Re: Some help with SimpleXML :`(
        297663 by: Matthew Croud
        297664 by: J DeBord

Re: What type of barcode used for document management system ?
        297665 by: Sam Stelfox

how to strip empty lines out of a txt using  preg_replace()
        297666 by: Ralph Deffke
        297667 by: Ashley Sheridan
        297668 by: Ralph Deffke
        297669 by: Ashley Sheridan
        297670 by: Ralph Deffke
        297671 by: Ashley Sheridan
        297672 by: Ralph Deffke
        297673 by: Ashley Sheridan
        297674 by: Martin Scotta
        297675 by: Ralph Deffke
        297676 by: Sam Stelfox
        297677 by: Ralph Deffke
        297678 by: Ashley Sheridan

Re: Converting URL's to hyperlinks.
        297679 by: Lupus Michaelis

Re: Searching on AlphaNumeric Content Only
        297680 by: Lupus Michaelis
        297681 by: Ashley Sheridan
        297682 by: Lupus Michaelis
        297683 by: Lupus Michaelis

php and ODBC
        297684 by: Marc Fromm

PHP inserting carriage returns into POST values?
        297685 by: James Colannino
        297686 by: Andrew Ballard
        297689 by: James Colannino

Include Files in HTML
        297687 by: sono-io.fannullone.us
        297688 by: Bob McConnell

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---

Well, you guys are awesome.

So the script below doesn't cause any errors (nice), however it doesn't save the newly added child to the xml file (items.xml):



$xml = simplexml_load_file("items.xml");

$item = $xml->addChild('item');
$item->addChild('name', $name);
$item->addChild('desc', $desc);
$item->addChild('size', $size);
$item->addChild('price', $price);



I thought it would ?  would i need to "write" using fwrite ?


--- End Message ---
--- Begin Message ---
On Fri, Sep 4, 2009 at 10:23 AM, Matthew Croud <m...@obviousdigital.com>wrote:

>
> Well, you guys are awesome.
>
> So the script below doesn't cause any errors (nice), however it doesn't
> save the newly added child to the xml file (items.xml):
>
>
>
> $xml = simplexml_load_file("items.xml");
>
> $item = $xml->addChild('item');
> $item->addChild('name', $name);
> $item->addChild('desc', $desc);
> $item->addChild('size', $size);
> $item->addChild('price', $price);
>
>
>
> I thought it would ?  would i need to "write" using fwrite ?
>
>
You'll need to save your xml to the file once you are done manipulating it.
Use $xml->asXML('filename'); Check here:
http://www.php.net/manual/en/simplexmlelement.asXML.php

J

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

--- End Message ---
--- Begin Message --- As a matter of fact... For a while I was using a barcode generator to test out inventory system before getting them professionally made. I personally chose to go with Interleaved 2 of 5 as our barcode scanner was able to read them accurately and it was the same format as our campus ID cards. The trick with this is that it only supports numbers. Code128 has three different encoding tables, table B which is most commonly used, includes the characters 0-9, A-Z, a-z and a handful of symbols which I don't remember of the top of my head.

I used a class someone else made which can be found here:
http://www.phpclasses.org/browse/package/2176.html

The code itself is quite ugly but as it was only needed temporarily it worked. It might be a good starting point for you though.

aveev wrote:
Hi, I'm new to using barcode....
I want to create an online registration in my application, where the user
can fill in the form and the application will create a pdf file of the form
with the barcode inserted on it. The user then brings the printed form to us
and we scan the barcode. After scanning the barcode and verifying the user
data, we will proceed to decide whether his/her application is approved or
not.
I'm using fpdf to create the pdf file and for the barcode, I'm still looking
for suitable solution.
I don't know what type of barcode I should use for this purpose (I've
browsed internet and found out many types of barcodes..e.g 39, 93, ean-13,
c128, etc).
Has anyone used php and barcode generator with their application ??

Thanks


--- End Message ---
--- Begin Message ---
Hi all, I'm a bit under stress, maybe somebody knows the regex on a snap.
using PHP_EOL would be great.

thanks
ralph_def...@yahoo.de



--- End Message ---
--- Begin Message ---
On Fri, 2009-09-04 at 14:58 +0200, Ralph Deffke wrote:
> Hi all, I'm a bit under stress, maybe somebody knows the regex on a snap.
> using PHP_EOL would be great.
> 
> thanks
> ralph_def...@yahoo.de
> 
> 
> 
The regex that would match a line containing only whitespace would look
like this:

^\s*$

Thanks,
Ash
http://www.ashleysheridan.co.uk




--- End Message ---
--- Begin Message ---
ok
 preg_replace( "/^\s*$/m", "", $somestring)
does not take empty lines out

"Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote in message
news:1252069539.24700.150.ca...@localhost...
> On Fri, 2009-09-04 at 14:58 +0200, Ralph Deffke wrote:
> > Hi all, I'm a bit under stress, maybe somebody knows the regex on a
snap.
> > using PHP_EOL would be great.
> >
> > thanks
> > ralph_def...@yahoo.de
> >
> >
> >
> The regex that would match a line containing only whitespace would look
> like this:
>
> ^\s*$
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>



--- End Message ---
--- Begin Message ---
On Fri, 2009-09-04 at 15:28 +0200, Ralph Deffke wrote:
> ok
>  preg_replace( "/^\s*$/m", "", $somestring)
> does not take empty lines out
> 
> "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote in message
> news:1252069539.24700.150.ca...@localhost...
> > On Fri, 2009-09-04 at 14:58 +0200, Ralph Deffke wrote:
> > > Hi all, I'm a bit under stress, maybe somebody knows the regex on a
> snap.
> > > using PHP_EOL would be great.
> > >
> > > thanks
> > > ralph_def...@yahoo.de
> > >
> > >
> > >
> > The regex that would match a line containing only whitespace would look
> > like this:
> >
> > ^\s*$
> >
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
> >
> 
> 
> 
Are the lines actually whitespace, or are they actually <br/> tags that
are inserting lines to format the page for HTML display?

Thanks,
Ash
http://www.ashleysheridan.co.uk




--- End Message ---
--- Begin Message ---
the problem is some have got \t\n
some are just \n\n....\n

using PHP_EOL is a must

I thing must be something with the /../sm attributes to the regex, spend
like half an hour, but didn't get it, I'm running against a dead line,
doesn't seem to be that easy if regex is not the everydays need u have


"Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote in message
news:1252071327.24700.152.ca...@localhost...
> On Fri, 2009-09-04 at 15:28 +0200, Ralph Deffke wrote:
> > ok
> >  preg_replace( "/^\s*$/m", "", $somestring)
> > does not take empty lines out
> >
> > "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote in message
> > news:1252069539.24700.150.ca...@localhost...
> > > On Fri, 2009-09-04 at 14:58 +0200, Ralph Deffke wrote:
> > > > Hi all, I'm a bit under stress, maybe somebody knows the regex on a
> > snap.
> > > > using PHP_EOL would be great.
> > > >
> > > > thanks
> > > > ralph_def...@yahoo.de
> > > >
> > > >
> > > >
> > > The regex that would match a line containing only whitespace would
look
> > > like this:
> > >
> > > ^\s*$
> > >
> > > Thanks,
> > > Ash
> > > http://www.ashleysheridan.co.uk
> > >
> > >
> > >
> >
> >
> >
> Are the lines actually whitespace, or are they actually <br/> tags that
> are inserting lines to format the page for HTML display?
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>



--- End Message ---
--- Begin Message ---
On Fri, 2009-09-04 at 15:37 +0200, Ralph Deffke wrote:
> the problem is some have got \t\n
> some are just \n\n....\n
> 
> using PHP_EOL is a must
> 
> I thing must be something with the /../sm attributes to the regex, spend
> like half an hour, but didn't get it, I'm running against a dead line,
> doesn't seem to be that easy if regex is not the everydays need u have
> 
> 
> "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote in message
> news:1252071327.24700.152.ca...@localhost...
> > On Fri, 2009-09-04 at 15:28 +0200, Ralph Deffke wrote:
> > > ok
> > >  preg_replace( "/^\s*$/m", "", $somestring)
> > > does not take empty lines out
> > >
> > > "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote in message
> > > news:1252069539.24700.150.ca...@localhost...
> > > > On Fri, 2009-09-04 at 14:58 +0200, Ralph Deffke wrote:
> > > > > Hi all, I'm a bit under stress, maybe somebody knows the regex on a
> > > snap.
> > > > > using PHP_EOL would be great.
> > > > >
> > > > > thanks
> > > > > ralph_def...@yahoo.de
> > > > >
> > > > >
> > > > >
> > > > The regex that would match a line containing only whitespace would
> look
> > > > like this:
> > > >
> > > > ^\s*$
> > > >
> > > > Thanks,
> > > > Ash
> > > > http://www.ashleysheridan.co.uk
> > > >
> > > >
> > > >
> > >
> > >
> > >
> > Are the lines actually whitespace, or are they actually <br/> tags that
> > are inserting lines to format the page for HTML display?
> >
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
> >
> 
> 
> 
If it is just made up of \t and \n then \s in the regex should match it,
as it's meant to match just whitespace characters. Where are you getting
the content from anyway?

Thanks,
Ash
http://www.ashleysheridan.co.uk




--- End Message ---
--- Begin Message ---
I'm working on DTD's

"Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote in message
news:1252071932.24700.153.ca...@localhost...
> On Fri, 2009-09-04 at 15:37 +0200, Ralph Deffke wrote:
> > the problem is some have got \t\n
> > some are just \n\n....\n
> >
> > using PHP_EOL is a must
> >
> > I thing must be something with the /../sm attributes to the regex, spend
> > like half an hour, but didn't get it, I'm running against a dead line,
> > doesn't seem to be that easy if regex is not the everydays need u have
> >
> >
> > "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote in message
> > news:1252071327.24700.152.ca...@localhost...
> > > On Fri, 2009-09-04 at 15:28 +0200, Ralph Deffke wrote:
> > > > ok
> > > >  preg_replace( "/^\s*$/m", "", $somestring)
> > > > does not take empty lines out
> > > >
> > > > "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote in message
> > > > news:1252069539.24700.150.ca...@localhost...
> > > > > On Fri, 2009-09-04 at 14:58 +0200, Ralph Deffke wrote:
> > > > > > Hi all, I'm a bit under stress, maybe somebody knows the regex
on a
> > > > snap.
> > > > > > using PHP_EOL would be great.
> > > > > >
> > > > > > thanks
> > > > > > ralph_def...@yahoo.de
> > > > > >
> > > > > >
> > > > > >
> > > > > The regex that would match a line containing only whitespace would
> > look
> > > > > like this:
> > > > >
> > > > > ^\s*$
> > > > >
> > > > > Thanks,
> > > > > Ash
> > > > > http://www.ashleysheridan.co.uk
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > > Are the lines actually whitespace, or are they actually <br/> tags
that
> > > are inserting lines to format the page for HTML display?
> > >
> > > Thanks,
> > > Ash
> > > http://www.ashleysheridan.co.uk
> > >
> > >
> > >
> >
> >
> >
> If it is just made up of \t and \n then \s in the regex should match it,
> as it's meant to match just whitespace characters. Where are you getting
> the content from anyway?
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>



--- End Message ---
--- Begin Message ---
On Fri, 2009-09-04 at 15:45 +0200, Ralph Deffke wrote:
> I'm working on DTD's
> 
> "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote in message
> news:1252071932.24700.153.ca...@localhost...
> > On Fri, 2009-09-04 at 15:37 +0200, Ralph Deffke wrote:
> > > the problem is some have got \t\n
> > > some are just \n\n....\n
> > >
> > > using PHP_EOL is a must
> > >
> > > I thing must be something with the /../sm attributes to the regex, spend
> > > like half an hour, but didn't get it, I'm running against a dead line,
> > > doesn't seem to be that easy if regex is not the everydays need u have
> > >
> > >
> > > "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote in message
> > > news:1252071327.24700.152.ca...@localhost...
> > > > On Fri, 2009-09-04 at 15:28 +0200, Ralph Deffke wrote:
> > > > > ok
> > > > >  preg_replace( "/^\s*$/m", "", $somestring)
> > > > > does not take empty lines out
> > > > >
> > > > > "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote in message
> > > > > news:1252069539.24700.150.ca...@localhost...
> > > > > > On Fri, 2009-09-04 at 14:58 +0200, Ralph Deffke wrote:
> > > > > > > Hi all, I'm a bit under stress, maybe somebody knows the regex
> on a
> > > > > snap.
> > > > > > > using PHP_EOL would be great.
> > > > > > >
> > > > > > > thanks
> > > > > > > ralph_def...@yahoo.de
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > The regex that would match a line containing only whitespace would
> > > look
> > > > > > like this:
> > > > > >
> > > > > > ^\s*$
> > > > > >
> > > > > > Thanks,
> > > > > > Ash
> > > > > > http://www.ashleysheridan.co.uk
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > >
> > > > Are the lines actually whitespace, or are they actually <br/> tags
> that
> > > > are inserting lines to format the page for HTML display?
> > > >
> > > > Thanks,
> > > > Ash
> > > > http://www.ashleysheridan.co.uk
> > > >
> > > >
> > > >
> > >
> > >
> > >
> > If it is just made up of \t and \n then \s in the regex should match it,
> > as it's meant to match just whitespace characters. Where are you getting
> > the content from anyway?
> >
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
> >
> 
> 
> 
OK, but where are they coming from? Are they as external files or what?

Thanks,
Ash
http://www.ashleysheridan.co.uk




--- End Message ---
--- Begin Message ---
On Fri, Sep 4, 2009 at 10:37 AM, Ralph Deffke <ralph_def...@yahoo.de> wrote:

> the problem is some have got \t\n
> some are just \n\n....\n
>
> using PHP_EOL is a must
>
> I thing must be something with the /../sm attributes to the regex, spend
> like half an hour, but didn't get it, I'm running against a dead line,
> doesn't seem to be that easy if regex is not the everydays need u have
>
>
> "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote in message
> news:1252071327.24700.152.ca...@localhost...
> > On Fri, 2009-09-04 at 15:28 +0200, Ralph Deffke wrote:
> > > ok
> > >  preg_replace( "/^\s*$/m", "", $somestring)
> > > does not take empty lines out
> > >
> > > "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote in message
> > > news:1252069539.24700.150.ca...@localhost...
> > > > On Fri, 2009-09-04 at 14:58 +0200, Ralph Deffke wrote:
> > > > > Hi all, I'm a bit under stress, maybe somebody knows the regex on a
> > > snap.
> > > > > using PHP_EOL would be great.
> > > > >
> > > > > thanks
> > > > > ralph_def...@yahoo.de
> > > > >
> > > > >
> > > > >
> > > > The regex that would match a line containing only whitespace would
> look
> > > > like this:
> > > >
> > > > ^\s*$
> > > >
> > > > Thanks,
> > > > Ash
> > > > http://www.ashleysheridan.co.uk
> > > >
> > > >
> > > >
> > >
> > >
> > >
> > Are the lines actually whitespace, or are they actually <br/> tags that
> > are inserting lines to format the page for HTML display?
> >
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
> >
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
The PHP_EOL is system dependent. If you want a solution that works on every
type of file you have to code it yourself. Here you have a function made
some time ago.
Maybe you can improve it.

If you want the result as a text format you can implode( PHP_EOL, $buffer )
Hope this helps you.

function explode($code)
{
    $lines = array();
    $buffer = '';

    for($i=0, $len = strlen($code); $i<$len; ++$i)
        switch( $code{$i} )
        {
            case "\r":
            case "\n":
                if( $i+1 == $len )
                    break 2;

                if( "\r" == ($next = $code{ $i+1 }) || "\n" == $next )
                {
                    ++$i;
                }

                $lines[] = $buffer;
                $buffer = '';
                break;
            default:
                $buffer .= $code{$i};
        }

    if( '' !== $buffer );
        $lines[] = $buffer;

    return $lines;
}


-- 
Martin Scotta

--- End Message ---
--- Begin Message ---
this works
$dtd = preg_replace( "/\n+/", "\n", $dtd);

"Martin Scotta" <martinsco...@gmail.com> wrote in message
news:6445d94e0909040653i44716f79m972f11055599...@mail.gmail.com...
> On Fri, Sep 4, 2009 at 10:37 AM, Ralph Deffke <ralph_def...@yahoo.de>
wrote:
>
> > the problem is some have got \t\n
> > some are just \n\n....\n
> >
> > using PHP_EOL is a must
> >
> > I thing must be something with the /../sm attributes to the regex, spend
> > like half an hour, but didn't get it, I'm running against a dead line,
> > doesn't seem to be that easy if regex is not the everydays need u have
> >
> >
> > "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote in message
> > news:1252071327.24700.152.ca...@localhost...
> > > On Fri, 2009-09-04 at 15:28 +0200, Ralph Deffke wrote:
> > > > ok
> > > >  preg_replace( "/^\s*$/m", "", $somestring)
> > > > does not take empty lines out
> > > >
> > > > "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote in message
> > > > news:1252069539.24700.150.ca...@localhost...
> > > > > On Fri, 2009-09-04 at 14:58 +0200, Ralph Deffke wrote:
> > > > > > Hi all, I'm a bit under stress, maybe somebody knows the regex
on a
> > > > snap.
> > > > > > using PHP_EOL would be great.
> > > > > >
> > > > > > thanks
> > > > > > ralph_def...@yahoo.de
> > > > > >
> > > > > >
> > > > > >
> > > > > The regex that would match a line containing only whitespace would
> > look
> > > > > like this:
> > > > >
> > > > > ^\s*$
> > > > >
> > > > > Thanks,
> > > > > Ash
> > > > > http://www.ashleysheridan.co.uk
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > > Are the lines actually whitespace, or are they actually <br/> tags
that
> > > are inserting lines to format the page for HTML display?
> > >
> > > Thanks,
> > > Ash
> > > http://www.ashleysheridan.co.uk
> > >
> > >
> > >
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> The PHP_EOL is system dependent. If you want a solution that works on
every
> type of file you have to code it yourself. Here you have a function made
> some time ago.
> Maybe you can improve it.
>
> If you want the result as a text format you can implode( PHP_EOL,
$buffer )
> Hope this helps you.
>
> function explode($code)
> {
>     $lines = array();
>     $buffer = '';
>
>     for($i=0, $len = strlen($code); $i<$len; ++$i)
>         switch( $code{$i} )
>         {
>             case "\r":
>             case "\n":
>                 if( $i+1 == $len )
>                     break 2;
>
>                 if( "\r" == ($next = $code{ $i+1 }) || "\n" == $next )
>                 {
>                     ++$i;
>                 }
>
>                 $lines[] = $buffer;
>                 $buffer = '';
>                 break;
>             default:
>                 $buffer .= $code{$i};
>         }
>
>     if( '' !== $buffer );
>         $lines[] = $buffer;
>
>     return $lines;
> }
>
>
> -- 
> Martin Scotta
>



--- End Message ---
--- Begin Message --- The following snippet is untested and using Ash's regex (it is accurate \s matches any white space). $content is what is getting stripped of the new lines and $filtered is the cleansed output. See if that does the trick for you.

$lines = str_split(PHP_EOL, $content);
$filtered = '';
foreach ($lines as $line) {
   if (!preg_match('^\s*$', $line)) {
// Splitting on the PHP_EOL characters cause it to be removed be sure to put it back
      $filtered .= $line . PHP_EOL;
   }
}

Ralph Deffke wrote:
the problem is some have got \t\n
some are just \n\n....\n

using PHP_EOL is a must

I thing must be something with the /../sm attributes to the regex, spend
like half an hour, but didn't get it, I'm running against a dead line,
doesn't seem to be that easy if regex is not the everydays need u have


"Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote in message
news:1252071327.24700.152.ca...@localhost...
On Fri, 2009-09-04 at 15:28 +0200, Ralph Deffke wrote:
ok
 preg_replace( "/^\s*$/m", "", $somestring)
does not take empty lines out

"Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote in message
news:1252069539.24700.150.ca...@localhost...
On Fri, 2009-09-04 at 14:58 +0200, Ralph Deffke wrote:
Hi all, I'm a bit under stress, maybe somebody knows the regex on a
snap.
using PHP_EOL would be great.

thanks
ralph_def...@yahoo.de



The regex that would match a line containing only whitespace would
look
like this:

^\s*$

Thanks,
Ash
http://www.ashleysheridan.co.uk




Are the lines actually whitespace, or are they actually <br/> tags that
are inserting lines to format the page for HTML display?

Thanks,
Ash
http://www.ashleysheridan.co.uk








--- End Message ---
--- Begin Message ---
and this is the PHP_EOL solution:
$dtd = preg_replace( "/[". PHP_EOL . "]+/", "". PHP_EOL . "", $dtd);

dont ask me why two empty strings are needed to surround the PHP_EOL but its
does it.

Why this works? we have got an INTERPRETER here any \n is transtlated into
0x0D an \r into 0x0A so the pattern does not reach prce as '\n' hehe


"Martin Scotta" <martinsco...@gmail.com> wrote in message
news:6445d94e0909040653i44716f79m972f11055599...@mail.gmail.com...
> On Fri, Sep 4, 2009 at 10:37 AM, Ralph Deffke <ralph_def...@yahoo.de>
wrote:
>
> > the problem is some have got \t\n
> > some are just \n\n....\n
> >
> > using PHP_EOL is a must
> >
> > I thing must be something with the /../sm attributes to the regex, spend
> > like half an hour, but didn't get it, I'm running against a dead line,
> > doesn't seem to be that easy if regex is not the everydays need u have
> >
> >
> > "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote in message
> > news:1252071327.24700.152.ca...@localhost...
> > > On Fri, 2009-09-04 at 15:28 +0200, Ralph Deffke wrote:
> > > > ok
> > > >  preg_replace( "/^\s*$/m", "", $somestring)
> > > > does not take empty lines out
> > > >
> > > > "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote in message
> > > > news:1252069539.24700.150.ca...@localhost...
> > > > > On Fri, 2009-09-04 at 14:58 +0200, Ralph Deffke wrote:
> > > > > > Hi all, I'm a bit under stress, maybe somebody knows the regex
on a
> > > > snap.
> > > > > > using PHP_EOL would be great.
> > > > > >
> > > > > > thanks
> > > > > > ralph_def...@yahoo.de
> > > > > >
> > > > > >
> > > > > >
> > > > > The regex that would match a line containing only whitespace would
> > look
> > > > > like this:
> > > > >
> > > > > ^\s*$
> > > > >
> > > > > Thanks,
> > > > > Ash
> > > > > http://www.ashleysheridan.co.uk
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > > Are the lines actually whitespace, or are they actually <br/> tags
that
> > > are inserting lines to format the page for HTML display?
> > >
> > > Thanks,
> > > Ash
> > > http://www.ashleysheridan.co.uk
> > >
> > >
> > >
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> The PHP_EOL is system dependent. If you want a solution that works on
every
> type of file you have to code it yourself. Here you have a function made
> some time ago.
> Maybe you can improve it.
>
> If you want the result as a text format you can implode( PHP_EOL,
$buffer )
> Hope this helps you.
>
> function explode($code)
> {
>     $lines = array();
>     $buffer = '';
>
>     for($i=0, $len = strlen($code); $i<$len; ++$i)
>         switch( $code{$i} )
>         {
>             case "\r":
>             case "\n":
>                 if( $i+1 == $len )
>                     break 2;
>
>                 if( "\r" == ($next = $code{ $i+1 }) || "\n" == $next )
>                 {
>                     ++$i;
>                 }
>
>                 $lines[] = $buffer;
>                 $buffer = '';
>                 break;
>             default:
>                 $buffer .= $code{$i};
>         }
>
>     if( '' !== $buffer );
>         $lines[] = $buffer;
>
>     return $lines;
> }
>
>
> -- 
> Martin Scotta
>



--- End Message ---
--- Begin Message ---
On Fri, 2009-09-04 at 16:13 +0200, Ralph Deffke wrote:
> and this is the PHP_EOL solution:
> $dtd = preg_replace( "/[". PHP_EOL . "]+/", "". PHP_EOL . "", $dtd);
> 
> dont ask me why two empty strings are needed to surround the PHP_EOL but its
> does it.
> 
> Why this works? we have got an INTERPRETER here any \n is transtlated into
> 0x0D an \r into 0x0A so the pattern does not reach prce as '\n' hehe
> 
> 
> "Martin Scotta" <martinsco...@gmail.com> wrote in message
> news:6445d94e0909040653i44716f79m972f11055599...@mail.gmail.com...
> > On Fri, Sep 4, 2009 at 10:37 AM, Ralph Deffke <ralph_def...@yahoo.de>
> wrote:
> >
> > > the problem is some have got \t\n
> > > some are just \n\n....\n
> > >
> > > using PHP_EOL is a must
> > >
> > > I thing must be something with the /../sm attributes to the regex, spend
> > > like half an hour, but didn't get it, I'm running against a dead line,
> > > doesn't seem to be that easy if regex is not the everydays need u have
> > >
> > >
> > > "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote in message
> > > news:1252071327.24700.152.ca...@localhost...
> > > > On Fri, 2009-09-04 at 15:28 +0200, Ralph Deffke wrote:
> > > > > ok
> > > > >  preg_replace( "/^\s*$/m", "", $somestring)
> > > > > does not take empty lines out
> > > > >
> > > > > "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote in message
> > > > > news:1252069539.24700.150.ca...@localhost...
> > > > > > On Fri, 2009-09-04 at 14:58 +0200, Ralph Deffke wrote:
> > > > > > > Hi all, I'm a bit under stress, maybe somebody knows the regex
> on a
> > > > > snap.
> > > > > > > using PHP_EOL would be great.
> > > > > > >
> > > > > > > thanks
> > > > > > > ralph_def...@yahoo.de
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > The regex that would match a line containing only whitespace would
> > > look
> > > > > > like this:
> > > > > >
> > > > > > ^\s*$
> > > > > >
> > > > > > Thanks,
> > > > > > Ash
> > > > > > http://www.ashleysheridan.co.uk
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > >
> > > > Are the lines actually whitespace, or are they actually <br/> tags
> that
> > > > are inserting lines to format the page for HTML display?
> > > >
> > > > Thanks,
> > > > Ash
> > > > http://www.ashleysheridan.co.uk
> > > >
> > > >
> > > >
> > >
> > >
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> > >
> > The PHP_EOL is system dependent. If you want a solution that works on
> every
> > type of file you have to code it yourself. Here you have a function made
> > some time ago.
> > Maybe you can improve it.
> >
> > If you want the result as a text format you can implode( PHP_EOL,
> $buffer )
> > Hope this helps you.
> >
> > function explode($code)
> > {
> >     $lines = array();
> >     $buffer = '';
> >
> >     for($i=0, $len = strlen($code); $i<$len; ++$i)
> >         switch( $code{$i} )
> >         {
> >             case "\r":
> >             case "\n":
> >                 if( $i+1 == $len )
> >                     break 2;
> >
> >                 if( "\r" == ($next = $code{ $i+1 }) || "\n" == $next )
> >                 {
> >                     ++$i;
> >                 }
> >
> >                 $lines[] = $buffer;
> >                 $buffer = '';
> >                 break;
> >             default:
> >                 $buffer .= $code{$i};
> >         }
> >
> >     if( '' !== $buffer );
> >         $lines[] = $buffer;
> >
> >     return $lines;
> > }
> >
> >
> > -- 
> > Martin Scotta
> >
> 
> 
> 
The empty strings are forcing the parameter to be used as a string,
otherwise the line would be translated as something like this:

$dtd = preg_replace( "/\n/", \n, $dtd);

Notice how that newline character is actually just the character by
itself, and is not a string.

Obviously, the exact end of line character will differ from system to
system, but this is a simple example of exactly why you had to
concatenate the PHP_EOL with those empty strings.

Thanks,
Ash
http://www.ashleysheridan.co.uk




--- End Message ---
--- Begin Message ---
Daevid Vincent a écrit :
Maybe I misunderstood the OP,
  OP ?

but wouldn't this (or something like it) be
easier and cleaner than that mess below??
  No, it's dirty too.

$url = preg_replace("/(\...@\w+\.[a-za-z]{2,3})/i", "<a
href='mailto:$1'>$1</a>", $url);
This violate the numerous RFC about mail addresses, and some other stuffs.


$url = preg_replace("/\s(http:\/\/)?(\w*\.?\w*\.[a-zA-Z]{2,3}.*?\s)/i", " <a
href='http://$2' target='_blank'>$2</a>", $url);

Same as previously. What about .info, .museum and so on tld ? The filter_var is well suited for this kind of job. Oh, and your regex isn't smart (you use the case insensitivity flag, but seek A-Z characters...) :D

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

--- End Message ---
--- Begin Message ---
Ashley Sheridan a écrit :
What's wrong with using the wildcards that are built into most SQL
variants?

  Performance issues. Like is an operator to avoid when possible.

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

--- End Message ---
--- Begin Message ---
On Fri, 2009-09-04 at 17:00 +0200, Lupus Michaelis wrote:
> Ashley Sheridan a écrit :
> > What's wrong with using the wildcards that are built into most SQL
> > variants?
> 
>    Performance issues. Like is an operator to avoid when possible.
> 
> -- 
> Mickaël Wolff aka Lupus Michaelis
> http://lupusmic.org
> 
You'll have far greater performance issues if you retrieve all those
records and attempt to do the same thing inside of PHP...

Thanks,
Ash
http://www.ashleysheridan.co.uk




--- End Message ---
--- Begin Message ---
sono...@fannullone.us a écrit :

Here's an example: let's say there is an itemID of 4D-2448-7PS but someone omits the dashes and searches on 4D24487PS. Is it possible in PHP to have the find be successful, even if the search criteria doesn't exactly match what's stored in the field?

I think you don't follow the good path. A good way could be to have a strenger UI management. For exemple, here, you have an ID that is composed about 3 bits. So do the UI present three input fields, or write a smart input (with JS).

Of course, in the control side (PHP), you have to check the format of the returned data. Here you can reject the input, or fall through some segment of code that try to interpret the submitted value. But in first time, do it simple and be rough to users. Usability can be improved in a second time.

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

--- End Message ---
--- Begin Message ---
Ashley Sheridan a écrit :

You'll have far greater performance issues if you retrieve all those
records and attempt to do the same thing inside of PHP...

It's why I speak about « avoiding » and not « bannishing ». Like can be usefull, I used to use it. But it is not the a good answer to all problems. The problem with like operator is it can't use the index (or in a very limited way). So I try to warn about it.

So said, I never submit an all-retrieving method. I know it isn't the solution too.

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

--- End Message ---
--- Begin Message ---
I am trying to figure out how to use ODBC with PHP.
Specifically I need to connect a php script to a SunGard Banner table
I know I need to set up some type of DNS connection, but I am not sure what 
exactly that is.

[r...@dev ~]$ odbcinst -j
unixODBC 2.2.11
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
USER DATA SOURCES..: /root/.odbc.ini

/etc/odbcinst.ini
  1 # Example driver definitinions
  2 #
  3 #
  4
  5 # Included in the unixODBC package
  6 [PostgreSQL]
  7 Description = ODBC for PostgreSQL
  8 Driver      = /usr/lib/libodbcpsql.so
  9 Setup       = /usr/lib/libodbcpsqlS.so
 10 FileUsage   = 1
 11
 12
 13 # Driver from the MyODBC package
 14 # Setup from the unixODBC package
 15 #[MySQL]
 16 #Description    = ODBC for MySQL
 17 #Driver     = /usr/lib/libmyodbc.so
 18 #Setup      = /usr/lib/libodbcmyS.so
 19 #FileUsage  = 1

Thanks,

Marc


--- End Message ---
--- Begin Message ---
Hey everyone.  I ran into a really weird issue that I was hoping I could
find some clarification on.  In short, I have javascript functions that
operate on hidden text values.  Those values may be posted, in which
case PHP then prints them back to the page via what comes in on $_POST.

The weird thing is, I was no longer able to match substrings inside
those hidden text values after posting via Javascript.  I banged my head
over this for a couple hours, until I realized that the string's length
was being increased by one after posting (I found this out in
javascript).  Upon further investigation, I found that all instances of
"substring\n" were being replaced by "substring(carriage return)\n"
after post.

For now, I'm simply doing str_replace(chr(13), "", $_POST['value'])
before re-inserting it into the HTML, but I was wondering why PHP is
inserting those extra characters.

Thanks!
James

--- End Message ---
--- Begin Message ---
On Fri, Sep 4, 2009 at 3:16 PM, James Colannino<ja...@colannino.org> wrote:
> Hey everyone.  I ran into a really weird issue that I was hoping I could
> find some clarification on.  In short, I have javascript functions that
> operate on hidden text values.  Those values may be posted, in which
> case PHP then prints them back to the page via what comes in on $_POST.
>
> The weird thing is, I was no longer able to match substrings inside
> those hidden text values after posting via Javascript.  I banged my head
> over this for a couple hours, until I realized that the string's length
> was being increased by one after posting (I found this out in
> javascript).  Upon further investigation, I found that all instances of
> "substring\n" were being replaced by "substring(carriage return)\n"
> after post.
>
> For now, I'm simply doing str_replace(chr(13), "", $_POST['value'])
> before re-inserting it into the HTML, but I was wondering why PHP is
> inserting those extra characters.
>
> Thanks!
> James
>

Are you sure it is PHP? Just a couple ideas...

Javascript interpolates \n as a newline character inside both double
and single quotes unlike PHP that only interpolates inside double
quotes. If the client browser is running under Windows, it may even be
possible that the \n is recognized by the browser as a line terminator
and converted to the Windows line terminator sequence (\r\n) either
inside the form element itself or in the Javascript you are using to
post back to the web server.

Andrew

--- End Message ---
--- Begin Message ---
Andrew Ballard wrote:

> Javascript interpolates \n as a newline character inside both double
> and single quotes unlike PHP that only interpolates inside double
> quotes. If the client browser is running under Windows, it may even be
> possible that the \n is recognized by the browser as a line terminator
> and converted to the Windows line terminator sequence (\r\n) either
> inside the form element itself or in the Javascript you are using to
> post back to the web server.

Both the server and the client are Linux machines, so there are no
issues with incompatible representations of newline.  I only ever place
\n's inside double quotes in PHP, and am aware of the fact that I don't
have to do that in PHP.  For the life of me, I just can't figure out
what's happening.

Anyway, for now, filtering \r's out in PHP seems to do the trick.

James

--- End Message ---
--- Begin Message --- In my readings, I've run across examples showing include files being called from within the <head></head> tags, and other examples showing them called within <body></body>. I've always put them in the header section myself, but I was wondering if one is better than the other, or is it just personal preference?

Frank

--- End Message ---
--- Begin Message ---
From: sono-io at fannullone.us

>       In my readings, I've run across examples showing include files
being  
> called from within the <head></head> tags, and other examples showing

> them called within <body></body>.  I've always put them in the header

> section myself, but I was wondering if one is better than the other,  
> or is it just personal preference?

Depends on what you are including. The only tags that can be inside the
head are <base>, <link>, <meta>, <script>, <style>,  and <title>.
Everything else is either body or prologue.

The full specs can be found at
<http://www.w3schools.com/tags/default.asp>.

Bob McConnell

--- End Message ---

Reply via email to