php-general Digest 13 Oct 2007 18:48:12 -0000 Issue 5071

Topics (messages 263176 through 263188):

Fast prefix search?
        263176 by: js
        263179 by: Nathan Nobbe
        263183 by: js
        263186 by: Nathan Nobbe
        263188 by: Robert Cummings

How to convert URL's to Links in User posted text in forms ?
        263177 by: Hemanth
        263178 by: Nathan Nobbe

Weird mystery error
        263180 by: Nathan Hawks
        263181 by: Nathan Nobbe
        263182 by: Nathan Hawks
        263184 by: Nathan Nobbe
        263185 by: Nathan Hawks
        263187 by: Nathan Nobbe

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

I'm writing a script which extracts text which starts with some string.
I tried to solve this by using Berkeley DB's B-tree and found that
PHP provides Berkeley DB  access through DBA[1] module.
But , as the doc says collectly,
"functionality is limited to a common subset of features"
so I couldn't fully utilize BDB. (especially lack of key_range[2] is
critical one)

I know it could be done by using RDBMS like MySQL
but using such is not so easy and fast compared to dbm solutions.

Are there any recommendations to solve this kind of problem?

Thank you in advance.

[1] http://php.oregonstate.edu/manual/en/ref.dba.php
[2] 
http://www.oracle.com/technology/documentation/berkeley-db/db/api_c/frame.html

--- End Message ---
--- Begin Message ---
On 10/13/07, js <[EMAIL PROTECTED]> wrote:
>
> HI.
>
> I'm writing a script which extracts text which starts with some string.


can you use the php string manipulation functions ?


-nathan

--- End Message ---
--- Begin Message ---
On 10/14/07, Nathan Nobbe <[EMAIL PROTECTED]> wrote:
> can you use the php string manipulation functions ?

I'll probably use strstr() to check whether a string starts with some prefix.
But problem I like to solve is how to effectively pick strings
starting with a prefix
from a large dataset, like a dictionary.

If Berkeley DB's set_range were available from PHP,
I could write something like

$word = dba_set_range($prefix, $dictionary) // get  the  first word
starting with $prefix
do {
  if (!prefix($word) == $prefix) break
  $found[] = $word
} while ($word = dba)_nextkey($dictionary))

--- End Message ---
--- Begin Message ---
On 10/13/07, js <[EMAIL PROTECTED]> wrote:
>
> On 10/14/07, Nathan Nobbe <[EMAIL PROTECTED]> wrote:
> > can you use the php string manipulation functions ?
>
> I'll probably use strstr() to check whether a string starts with some
> prefix.
> But problem I like to solve is how to effectively pick strings
> starting with a prefix
> from a large dataset, like a dictionary.
>
> If Berkeley DB's set_range were available from PHP,
> I could write something like
>
> $word = dba_set_range($prefix, $dictionary) // get  the  first word
> starting with $prefix
> do {
>   if (!prefix($word) == $prefix) break
>   $found[] = $word
> } while ($word = dba)_nextkey($dictionary))



how big is your dataset; have you tested against a potential data set and
gotten
long execution times?

foreach($dictionary as $curValue) {
    if((strpos($curValue, $prefix) != false) {
       $found[] = $curValue;
    }
}

notice how i used strpos rather than strstr, because i got this tip from the
docs
*Note: * If you only want to determine if a particular *needle* occurs
within *haystack*,
use the faster and less memory intensive function
strpos()<http://www.php.net/manual/en/function.strpos.php>instead.

there are some optimization points as well.  if you use a for loop, i think
it
will run a hair faster than the foreach, just make sure to store the length
of the
dictionary in an variable and use that as the sentinel control variable.
also, if
your search can be case insensitive you can use stripos instead of strpos,
that will
probly get you a little speed bump as well.

if the string methods in a loop are too doggy due to the size of your
datasets,
you might write a program that uses berkdb and call it using the shell from
within php.

-nathan

--- End Message ---
--- Begin Message ---
On Sun, 2007-10-14 at 02:07 +0900, js wrote:
> On 10/14/07, Nathan Nobbe <[EMAIL PROTECTED]> wrote:
> > can you use the php string manipulation functions ?
> 
> I'll probably use strstr() to check whether a string starts with some prefix.

>From the help for PHP's strstr() function:

    "Note: If you only want to determine if a particular
     needle occurs within haystack, use the faster and
     less memory intensive function strpos() instead."

So don't use strstr() use strpos(). Specifically use it like follows:

    if( strpos( $haystack, $prefix ) === 0 )
    {
        // it's a prefix.
    }

This wasn't particularly meant to address the original question, only
the improper use of strstr() for checking if one string exists within
another.

Cheers,
Rob.
-- 
...........................................................
SwarmBuy.com - http://www.swarmbuy.com

    Leveraging the buying power of the masses!
...........................................................

--- End Message ---
--- Begin Message ---
Hi,
I am trying to display as links the url's posted in the forms
<textarea> at my site valueads_dot_biz

I am removing all codes and special chars when they post to avoid any injection

but when i retrive back form the database and display
I want to find the url's in the text and display as clickable links.

I found many examples in the php manual and on the web..

but still having hiccups

I'd like some suggestions form you people.

Regards
Hemanth
Bangalore, India

--- End Message ---
--- Begin Message ---
On 10/13/07, Hemanth <[EMAIL PROTECTED]> wrote:
>
> Hi,
> I am trying to display as links the url's posted in the forms
> <textarea> at my site valueads_dot_biz
>
> I am removing all codes and special chars when they post to avoid any
> injection
>
> but when i retrive back form the database and display
> I want to find the url's in the text and display as clickable links.
>
> I found many examples in the php manual and on the web..
>
> but still having hiccups
>
> I'd like some suggestions form you people.


how are you extracting the links from the text people submit?
id recommend you search the web for some free regex that matches a url and
use that
to extract the links.   or write your own regex :)
also, how do people get to add links?  on gmail and many other systems there
is a
purpose built button that allows you to transform highlighted text into a
link.  if you had
something like that you could handle those links specially.  i might append
a class attribute
of those anchor tags.  then when the form is submitted, grab all those
anchor tags and place
special tags that your application knows about around them.  that way when
you grab the
text back out of the database, you can easily find those links and strip the
special delimiters
off.

-nathan

--- End Message ---
--- Begin Message ---
Hey all,

I wrote a symfony app this week for a client, and I'm trying to install
it on their server today.  I am getting a Fatal that I can only assume
is either an Apache 1.3.37 bug, or a PHP 5.2.4 bug.  It's madness.  PHP
is reporting an undefined function, but it's undefined because it's only
a few random letters of the actual function expression in the code.
It's parsing random substrings as functions.  Check this out:

Source of /search/search.php:

Line 1:  <?php
Line 2:  define('SF_ROOT_DIR',    '../../sf_basedir');
Line 3:  define('SF_APP',         'search');
Line 4:  define('SF_ENVIRONMENT', 'prod');
Line 5:  define('SF_DEBUG',       true);
Line 6:  //define('SF_DEBUG',       false);
Line 7:
Line 8:
require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');
Line 9:
Line 10: sfContext::getInstance()->getController()->dispatch();
<<EOF

I get this _awesome_ fatal error:

[13-Oct-2007 10:53:42] PHP Fatal error:  Call to undefined function  e()
in [yadda/yadda]/search/search.php on line 11

Now, I know for sure that ../../sf_basedir is the right folder - and get
this - I know this because the script begins to run.  If you're
symfony-aware, it loads and presents my layout, but no contents.  I'm
sure you can spot the e() in the code on line 10, and, an hour or so
ago, the error was slightly different:

Call to undefined function  troller() (in file yadda) on line 11

(see line 10 above to find the "troller")

I did a week of testing on this code, on PHP 5.2.4 and Apache 2.2,
before installing it.  Everything worked and all symfony's unit tests
passed.  It is rock solid.  Now I am having autoloading nightmares
(having to move all my classes into the one directory it successfully
finds files in on the client's host.)

So ... keeping in mind that it can parse search.php well enough to show
me the app layout (via php) and fire the symfony engine ... what causes
Apache or PHP to then double back and do this with the parser?

Oh one more note:  I am using ncftp, and I'm aware it likes to resume
when it shouldn't, so I've been deleting the files to be replaced and
and the cache subfolders, reloading the page to show the webserver it's
gone, and then uploading the replacement files - just a procedure that
I've learned ncftp sometimes necessitates.  

Any help would be greatly appreciated, I'm scrambling.

--- End Message ---
--- Begin Message ---
are there any php extensions your code requires that arent on the production
system?
have you checked the php.ini settings on the new host to ensure theyre the
same as your test box?
that would be a good idea no matter what, and you might turn something up
regarding your problem.

can you run the symphony unit tests on the new box?  they might expose a
problem.
setup everything the same as you have it on your test box then execute the
unit tests.

-nathan

--- End Message ---
--- Begin Message ---
I don't use lists regularly, sorry for the double-reply to Nathan.


Sadly:
 - no ssh on the client box
 - can't 100% mimic because I have a different Apache

However, I did use symfony freeze to move all the Pear modules etc that
it needs, into the local site.  

An additional clue might be:  the first problem I had was that
autoloading wasn't working at all, until I moved all the files it needed
into one of the symfony lib dirs (it wouldn't seek into my app dirs)

I see a couple things in their phpinfo that concern me... does anybody
see a warning flag here?

The customer's site was compiled with --enable-force-cgi-redirect ...
and the server_software row says PHP5 was compiled CGI only... mine was
compiled with apxs2.

They have something called sourceguardian, never heard of it but my
source was fine till this webserver got ahold of it...

?

Ps:  I have 4 other apps installed in this project and they all work
fine :\  Believe me, in a file as short as a symfony front controller,
and after checking about 40 times, I'm pretty sure the file is OK :)

--- End Message ---
--- Begin Message ---
On 10/13/07, Nathan Hawks <[EMAIL PROTECTED]> wrote:
>
> Ps:  I have 4 other apps installed in this project and they all work
> fine :\  Believe me, in a file as short as a symfony front controller,
> and after checking about 40 times, I'm pretty sure the file is OK :)
>

is this the first symphony app you have on the box?

-nathan

--- End Message ---
--- Begin Message ---
I think I misunderstood the question.  All 5 apps in the project are
installed on their server, and all working at 99-100% except this one.
(can't be sure the rest is bug free because this is my white whale at
the moment)

On Sat, 2007-10-13 at 13:13 -0400, Nathan Nobbe wrote:
> On 10/13/07, Nathan Hawks <[EMAIL PROTECTED]> wrote:
>         Ps:  I have 4 other apps installed in this project and they
>         all work
>         fine :\  Believe me, in a file as short as a symfony front
>         controller,
>         and after checking about 40 times, I'm pretty sure the file is
>         OK :)
> 
> is this the first symphony app you have on the box?
> 
> -nathan

--- End Message ---
--- Begin Message ---
On 10/13/07, Nathan Hawks <[EMAIL PROTECTED]> wrote:
>
> I think I misunderstood the question.  All 5 apps in the project are
> installed on their server, and all working at 99-100% except this one.
> (can't be sure the rest is bug free because this is my white whale at
> the moment)


are the 5 apps all using symphony?
if you have other apps running on symphony on the production box, then
id imagine apache version and php version can be rulled out.
i would try to devise some method of determining why the autoloading isnt
working on the production box.

otherwise you might read up on symphony.  see if there is anything about
configuration differences w/ mod_rewrite for apache 1.3 or 2.2

how do you setup mod_rewrite for symphony anyway? do they have you put
some configuration directives in httpd.conf or something?

-nathan

--- End Message ---

Reply via email to