php-general Digest 3 Sep 2009 12:41:35 -0000 Issue 6320

Topics (messages 297618 through 297629):

Re: Converting URL's to hyperlinks.
        297618 by: Daevid Vincent

Re: Array references - how to unset() ?
        297619 by: Martin Zvarík

Searching on AlphaNumeric Content Only
        297620 by: sono-io.fannullone.us
        297621 by: German Geek
        297622 by: Ben Dunlap
        297624 by: Ashley Sheridan
        297626 by: Andrea Giammarchi
        297628 by: Andrea Giammarchi

Re: Date Comparison
        297623 by: J DeBord
        297627 by: Stuart

Re: CodeWorks 09
        297625 by: Luke

Re: a doubt with class DOM
        297629 by: Raymond Irving

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 ---
Maybe I misunderstood the OP, but wouldn't this (or something like it) be
easier and cleaner than that mess below??

$url = preg_replace("/(\...@\w+\.[a-za-z]{2,3})/i", "<a
href='mailto:$1'>$1</a>", $url);

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


> -----Original Message-----
> From: Nisse Engström [mailto:[email protected]] 
> Sent: Saturday, August 29, 2009 1:46 PM
> To: [email protected]
> Subject: Re: [PHP] Converting URL's to hyperlinks.
> 
> On Fri, 28 Aug 2009 17:22:20 -0600, LinuxManMikeC wrote:
> 
> > <a href="<?php echo $url; ?>">click here</a>
> 
> *Groan*
> 
> Throw any random web site to an HTML validator
> and you're likely to see this kind of slop all
> over.
> 
> The correct solution is of course:
> 
>   $u = htmlspecialchars ($url);
>   echo "<a href=\"$u\">$u</a>";
> 
> 
> [A more elaborate way to flay this feline is
>  included below.]
> 
> 
> /Nisse
> 
> 
> /* Reworked from slightly different code.
>    Bugs may have been introduced.         */
> 
> <?php
> 
>   function url_to_links ($url)
>   {
>     if (preg_match ('@^([a-z]+://)(.*)@i', $url, $m)) {
>       $prfx = $m[1];
>       $path = $m[2];
>     } else {
>       return htmlspecialchars ($url);
>     }
> 
>     $url_sofar = $prfx;
>     $links = htmlspecialchars ($prfx);
> 
>     $segs = explode ('?', $path, 2);
>     if (isset ($segs[1]))
>       $query = $segs[1];
>     $segs = explode ('/', $segs[0]);
> 
>     for ($segn = 0; $segn < count ($segs); $segn++) {
>       $url_sofar .= $segs[$segn];
>       if (isset ($segs[$segn+1]))
>         $url_sofar .= '/';
> 
>       if ($segs[$segn] !== '') {
>         $links .= '<a href="' . htmlspecialchars ($url_sofar) . '">'
>                . htmlspecialchars ($segs[$segn]) . '</a>';
>       }
> 
>       if (isset ($segs[$segn+1]))
>         $links .= '/';
>     }
> 
>     if (isset ($query)) {
>       $url_sofar .= "?$query";
>       $links .= '?<a href="' . htmlspecialchars ($url_sofar)
>              .  '">' . htmlspecialchars ($query) . '</a>';
>     }
> 
>     return $links;
>   }
> 
>   $u = 'https://ebagwa.example/abd/def/ghi?s=t&u=v&w=x&y=z';
>   $u_h = htmlspecialchars ($u);
>   $links = url_to_links ($u);
> 
>   header ('Content-Type: text/html');
> 
>   echo <<<_
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
>   "http://www.w3.org/TR/html4/strict.dtd";>
> <title>url_to_links()</title>
> 
> <pre>
> $u_h
>   &#x2193;
> $links
> </pre>
> 
> _;
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


--- End Message ---
--- Begin Message ---
AHA !!!

OMG... how come I did not see that!?

Instead this:
$array =& $array[$final];
unset($array);

This:
unset($array[$final]);


3 AM in the morning... that must be the reason! .)

Thanks.




This is possible. You're just not giving enough consideration to your exit strategy :)

<?php

function unset_deep( &$array, $keys )
{
    $final = array_pop( $keys );

    foreach( $keys as $key )
    {
        $array = &$array[$key];
    }

    unset( $array[$final] );
}

$value = array
(
    'a' => array
    (
        'b' => array
        (
            'c' => 'C',
            'd' => 'D',
            'e' => 'E'
        ),
    ),
);

$keys = array('a', 'b', 'c');
unset_deep( $value, $keys );

print_r( $value );

?>

Cheers,
Rob.


--- End Message ---
--- Begin Message --- Is there is a way to search only for the alphanumeric content of field in a db? I have an itemID field that contains item #'s that include dashes, forward slashes, etc, and I want people to be able to search for an item # even if they don't enter the punctuation exactly.

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?

If this is possible, I'd appreciate it if someone could just point me in the right direction so I can read up on it.

Thanks,
Frank

--- End Message ---
--- Begin Message ---
Hi,

It's definitely possible to do when you do it in PHP, but not sure about on
the database side. You could read all records into memory and then iterate
over it with something like:

$toSearch = "4D24487PS"
$charsToIgnore = array('-','+',...);

foreach ($items as $k=>$item) {
  $itemVal = str_replace($charsToIgnore, '', $item);
  if (strcmp(str_replace($charsToIgnore, '', $toSearch), $itemVal) == 0) {
    $return = $item;
    break;
  }
}

This however might use a lot of memory, but if your DB is a manageable size
it should be ok. You can probably optimise it by iterating over a db result
set instead of reading everything into an array.

Cheers,
Tim
++Tim Hinnerk Heuer++

http://www.ihostnz.com

2009/9/3 <[email protected]>

>        Is there is a way to search only for the alphanumeric content of
> field in a db?  I have an itemID field that contains item #'s that include
> dashes, forward slashes, etc, and I want people to be able to search for an
> item # even if they don't enter the punctuation exactly.
>
>        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?
>
>        If this is possible, I'd appreciate it if someone could just point
> me in the right direction so I can read up on it.
>
> Thanks,
> Frank
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
>        Is there is a way to search only for the alphanumeric content of
> field in a db?  I have an itemID field that contains item #'s that include
> dashes, forward slashes, etc, and I want people to be able to search for an
> item # even if they don't enter the punctuation exactly.

Not sure if there's anything specifically PHP-ish that will help you
here, but I would be inclined to start by storing a stripped-down
version of the item ID (alphanumeric characters only) in a separate
column in the database table.

Then, when a user enters some search data, I would remove
non-alphanumeric characters, if any, from the user's input, and then
search the stripped column with this normalized version of the input.

If you want even fuzzier matching (inadvertent transpositions or an
omitted character or two OK, for example), you might read about
Levenshtein distance:

http://en.wikipedia.org/wiki/Levenshtein_distance

PHP has a levenshtein function but you'll have to figure out a way to
use it efficiently with your data set. Or, if Levenshtein isn't quite
right for your needs, the article above might at least point you in a
useful direction.

Ben

--- End Message ---
--- Begin Message ---
On Wed, 2009-09-02 at 21:30 -0700, Ben Dunlap wrote:
> >        Is there is a way to search only for the alphanumeric content of
> > field in a db?  I have an itemID field that contains item #'s that include
> > dashes, forward slashes, etc, and I want people to be able to search for an
> > item # even if they don't enter the punctuation exactly.
> 
> Not sure if there's anything specifically PHP-ish that will help you
> here, but I would be inclined to start by storing a stripped-down
> version of the item ID (alphanumeric characters only) in a separate
> column in the database table.
> 
> Then, when a user enters some search data, I would remove
> non-alphanumeric characters, if any, from the user's input, and then
> search the stripped column with this normalized version of the input.
> 
> If you want even fuzzier matching (inadvertent transpositions or an
> omitted character or two OK, for example), you might read about
> Levenshtein distance:
> 
> http://en.wikipedia.org/wiki/Levenshtein_distance
> 
> PHP has a levenshtein function but you'll have to figure out a way to
> use it efficiently with your data set. Or, if Levenshtein isn't quite
> right for your needs, the article above might at least point you in a
> useful direction.
> 
> Ben
> 

What's wrong with using the wildcards that are built into most SQL
variants?

SELECT * FROM table WHERE item_id LIKE '%#abcdef'

Will select all records where the item_id field ends in '#abcdef'

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




--- End Message ---
--- Begin Message ---
Which DB?
If it is MySQL, as example, you can simply use REGEXP syntax "^[a-zA-Z0-9]+$" 
via SELECT

Regards

> From: [email protected]
> To: [email protected]
> Date: Wed, 2 Sep 2009 20:47:15 -0700
> Subject: [PHP] Searching on AlphaNumeric Content Only
> 
>       Is there is a way to search only for the alphanumeric content of  
> field in a db?  I have an itemID field that contains item #'s that  
> include dashes, forward slashes, etc, and I want people to be able to  
> search for an item # even if they don't enter the punctuation exactly.
> 
>       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?
> 
>       If this is possible, I'd appreciate it if someone could just point me  
> in the right direction so I can read up on it.
> 
> Thanks,
> Frank
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

_________________________________________________________________
Drag n’ drop—Get easy photo sharing with Windows Live™ Photos.

http://www.microsoft.com/windows/windowslive/products/photos.aspx

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

> Indeed you could do it via a regexp, but that uses up quite some memory. 
> Every time you do a SELECT. You can simply add a table column with the 
> stripped value and let the table update itself (with an ON UPDATE ON 
> INSERT trigger, which takes the input value for the itemID and strips it 
> once).
> 
> When doing this on inputting the value into the database, you save 
> yourself the pain (and performance) of doing it on every SELECT-query.

Excuse me? Somebody suggested a PHP loop to solve a query problem and you are 
saying that REGEXP should not be used?
MySQL caches queries and 100 SELECT with a REGEXP will cost zero after the 
first one if nothing changed inside the table.

At the same time an internal REGEXP is faster than everything else has to move 
out and be parsed after via, probably, the same REGEXP engine. Try some bench.

This problem, imho, is a non-problem, at least not a PHP problem.

How MySQL optimizes internally REGEXPs is not PHP problem as well.

It's like to create a loop to read byte after byte because file_get_contents 
could be memory greedy (if you do that with 1 Gb of file you are you doing 
wrong in any case, logs need to be split as example) or avoid MATCH AGAINST in 
query if we have too many rows because of performances problem (table could be 
slipt as well to optimize performances) ... and these practices to avoid native 
solutions are a bit hilarious, imho.

Regards

_________________________________________________________________
Drag n’ drop—Get easy photo sharing with Windows Live™ Photos.

http://www.microsoft.com/windows/windowslive/products/photos.aspx

--- End Message ---
--- Begin Message ---
Telling someone RTFM is just rude and mean. Manipulating dates and times can
be confusing for beginners and experienced people alike. I would suggest
that when a question asked here causes you to respond with RTFM, don't
respond at all. Save yourself the time and trouble and save the person
asking the question the grief of being insulted. And Tedd your condescending
response caused me to lose respect for you. I'm sure the OP would have been
more than thankful to receive the same response without the RTFM. I'll read
any response to this, but I won't have anything more to say. This list has
been polluted enough lately with nonsense. Incredible.


On Sat, Aug 29, 2009 at 3:44 PM, tedd <[email protected]> wrote:

> At 1:01 PM -0400 8/28/09, David Stoltz wrote:
>
>> Hey Stuart -
>>
>> RTFM yourself....I did read it, and obviously misunderstood...
>>
>> I'm really sorry to bother you. I thought that was what a listserv like
>> this was for - to ask questions...
>>
>> I'll try not to ask questions I should know the answer to next time.
>>
>
> Whoa dude!
>
> You just received advice from a brilliant man and you are bitching about
> it?!?
>
> Look child, you are being told what you should do by a professional who is
> donating his time freely to help you. Just how did you not understand that?
>
> So, just do what he advised and say "Thank you sir, may I have another?"
>
> I've posted some dumb-ass questions before, but only after I took the time
> to research the question myself. And when someone took the time to
> straighten me out and help, I appreciated it.
>
> Hopefully next time you'll read the manual and take the time to understand
> what you read -- it would cut down on post that demonstrate just how
> ignorant and thankless you are at this.
>
> 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
>
>

--- End Message ---
--- Begin Message ---
2009/9/3 J DeBord <[email protected]>:
> Telling someone RTFM is just rude and mean. Manipulating dates and times can
> be confusing for beginners and experienced people alike. I would suggest
> that when a question asked here causes you to respond with RTFM, don't
> respond at all. Save yourself the time and trouble and save the person
> asking the question the grief of being insulted. And Tedd your condescending
> response caused me to lose respect for you. I'm sure the OP would have been
> more than thankful to receive the same response without the RTFM. I'll read
> any response to this, but I won't have anything more to say. This list has
> been polluted enough lately with nonsense. Incredible.

You're entitled to your opinion as much as I am, and my opinion is
that not making it clear to people that the answer to their question
is plainly obvious in the manual is just as rude if not more so than
suggesting they RTFM.

I make a point to never just say RTFM but to also answer the question
at the same time, but IMHO not telling people how fundamental their
question was does not help them in the long run. At the end of the day
it just encourages them to continue to rely on this list rather than
learning how to find the answer themselves and to only use this list
as a last resort.

I make no apology for my attitude towards this type of question, and
if you don't like it you can stick it where the sun don't shine.

-Stuart

-- 
http://stut.net/

> On Sat, Aug 29, 2009 at 3:44 PM, tedd <[email protected]> wrote:
>
>> At 1:01 PM -0400 8/28/09, David Stoltz wrote:
>>
>>> Hey Stuart -
>>>
>>> RTFM yourself....I did read it, and obviously misunderstood...
>>>
>>> I'm really sorry to bother you. I thought that was what a listserv like
>>> this was for - to ask questions...
>>>
>>> I'll try not to ask questions I should know the answer to next time.
>>>
>>
>> Whoa dude!
>>
>> You just received advice from a brilliant man and you are bitching about
>> it?!?
>>
>> Look child, you are being told what you should do by a professional who is
>> donating his time freely to help you. Just how did you not understand that?
>>
>> So, just do what he advised and say "Thank you sir, may I have another?"
>>
>> I've posted some dumb-ass questions before, but only after I took the time
>> to research the question myself. And when someone took the time to
>> straighten me out and help, I appreciated it.
>>
>> Hopefully next time you'll read the manual and take the time to understand
>> what you read -- it would cut down on post that demonstrate just how
>> ignorant and thankless you are at this.
>>
>> 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

--- End Message ---
--- Begin Message ---
2009/9/2 Ben Dunlap <[email protected]>

> > What I would do for UK PHP events :-(
>
> Something like this perhaps?
>
> http://conference.phpnw.org.uk/phpnw09/
>
> Ben
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Nice one, I might be able to get to that one :)

Thanks,

-- 
Luke Slater
:O)

this text is protected by international copyright. it is illegal for
anybody apart from the recipient to keep a copy of this text.
dieser text wird von internationalem urheberrecht geschuetzt. allen
ausser dem/der empfaenger/-in ist untersagt, eine kopie dieses textes
zu behalten.

--- End Message ---
--- Begin Message ---
It works ok for me and I think it's very reliable. You might want to run a few 
test on it though.

Another approach is to break up your xml into smaller documents and then use 
php string functions to merge them together.

__
Raymond Irving
Rich Ajax/PHP Development 
http://raxanpdi.com


--- On Wed, 9/2/09, Carlos Garcia <[email protected]> wrote:

From: Carlos Garcia <[email protected]>
Subject: [PHP] a doubt with class DOM
To: [email protected]
Date: Wednesday, September 2, 2009, 1:02 AM



if my xml is something big, how reliable is saving changes to my xml this way:

 

$doc->save('file.xml');

 

or another shape of save changes of my xml?

 

Sorry my english is bad =P.-

 

Thanks.-

 

Best regards, Karl.-
 
Carlos A. Garcia Hernandez



José Clemente Orozco Mza. 7 Lt. 14 Pedro Ojeda Paullada Ecatepec, Edo. De 
México / T: +(52 55) 57809620 / E: [email protected] / W: www.imkarl.net
 
Por favor considere sus responsabilidades ecológicas, no imprima este documento 
a menos que sea realmente necesario. / Please consider your ecological 
responsibilities. Don't print this e-mail unless you really need to.
 
AVISO DE CONFIDENCIALIDAD: Este mensaje de correo electrónico incluyendo en su 
caso los archivos adjuntos al mismo, pueden contener información de carácter 
confidencial y/o privilegiada, y se envían única y exclusivamente a la atención 
de la persona y/o entidad a quien va dirigido. La copia, revisión, uso, 
revelación y/o distribución de dicha información, sin autorización por escrito 
de Carlos A. García Hernández está prohibida. Si usted no es el destinatario a 
quien se dirige el presente correo, favor de contactar al remitente 
respondiendo al presente correo y eliminar el original incluyendo los archivos, 
así como cualesquiera copia del mismo. Mediante la recepción del presente 
correo usted reconoce y acepta que en caso de incumplimiento de su parte y/o de 
sus representantes a los términos antes descritos, Carlos A. García Hernández 
tendrá derecho a los daños y perjuicios que esto le ocasione.


CONFIDENTIALITY NOTICE: This e-mail message including attachments, may contain 
confidential and/or privileged material and only for the person or entity to 
which it is addressed. Any use, review, disclosure or distribution of such 
confidential information without the written authorization of Carlos A. García 
Hernández is prohibited. If you are not the intended recipient, please contact 
the sender by reply e-mail and destroy all copies of the original message 
including attachments. By receiving this e-mail you acknowledge that a breach 
by you and/or your representatives of the above provisions may entitle Carlos 
A. García Hernández to seek for damages.


_________________________________________________________________
Feliz aniversario Messenger!
www.aniversariomessenger.com.mx

--- End Message ---

Reply via email to