php-general Digest 26 Oct 2009 02:17:20 -0000 Issue 6410
Topics (messages 299316 through 299332):
Re: How to Get the Sub Classes of a Parent Class
299316 by: Raymond Irving
299319 by: David Otton
RewriteRule to hide PHP vars in URL
299317 by: Rob Gould
299321 by: Ashley Sheridan
299324 by: Rob Gould
299325 by: Ashley Sheridan
299327 by: ×× ××× ×× ××
299332 by: kranthi
how to replace many spaces with one space?
299318 by: Jeffry Lunggot
299320 by: David Otton
299322 by: Ashley Sheridan
299328 by: Al
[SOLVED] Re: [PHP] cannot compile PHP 5.2.11 on Mac OS X 10.6.1
299323 by: Mari Masuda
strange issue with PHP $basename, first character in filename missing (FreeBSD)
299326 by: Per olof Ljungmark
getcsv error
299329 by: Brian Hazelton
299330 by: Brian Hazelton
299331 by: Brian Hazelton
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 ---
I want to automatically initialize a specific sub class when the php page is
loaded.
I'm looking for a solution for php 5.1+ or anything that's optimized for 5.3
________________________________
From: David Otton <phpm...@jawbone.freeserve.co.uk>
To: Raymond Irving <xwis...@yahoo.com>
Cc: php-gene...@lists.php.net
Sent: Sun, October 25, 2009 8:44:40 AM
Subject: Re: [PHP] How to Get the Sub Classes of a Parent Class
2009/10/25 Raymond Irving <xwis...@yahoo.com>:
> Hello,
>
> Does any know of an optimized solution to get all the subclasses for a parent
> class?
That's not exactly a typical thing to want, although I can see a
couple of ways to do it... what exactly are you trying to do, and are
you using PHP5.3?
--- End Message ---
--- Begin Message ---
2009/10/25 Raymond Irving <xwis...@yahoo.com>:
> I want to automatically initialize a specific sub class when the php page is
> loaded.
>
> I'm looking for a solution for php 5.1+ or anything that's optimized for 5.3
You may be able solve this with a simple class_exists() (pseudo-code ahead):
if(class_exists($var)) {
$class = new $var;
} else {
$class = new FourOhFour;
}
--- End Message ---
--- Begin Message ---
I'm trying to follow the RewriteRule docs to make it so that:
http://benchwarmersports.com/packages/super-bowl-xliv/1
can be entered into the web-browser, and it transforms into:
http://benchwarmersports.com/packages.php?title=super-bowl-xliv&eventid=1
The good news is that it does transform the url when I do this. The
bad news
is that it also attempts to transform all the links (including to JS
files
and images).
Can someone tell me what I'd need to modify to avoid this problem
with the
RewriteRule?
My .htaccess file presently looks like this:
Options +FollowSymlinks
RewriteEngine On
RewriteOptions MaxRedirects=10
RewriteBase /
RewriteRule ^packages/([^/]+)/([^/]+)$ /packages.php?title=
$1&eventid=$2 [NC]
--- End Message ---
--- Begin Message ---
On Sun, 2009-10-25 at 11:04 -0400, Rob Gould wrote:
> I'm trying to follow the RewriteRule docs to make it so that:
>
> http://benchwarmersports.com/packages/super-bowl-xliv/1
>
> can be entered into the web-browser, and it transforms into:
>
> http://benchwarmersports.com/packages.php?title=super-bowl-xliv&eventid=1
>
>
> The good news is that it does transform the url when I do this. The
> bad news
> is that it also attempts to transform all the links (including to JS
> files
> and images).
>
> Can someone tell me what I'd need to modify to avoid this problem
> with the
> RewriteRule?
>
>
> My .htaccess file presently looks like this:
>
>
> Options +FollowSymlinks
> RewriteEngine On
> RewriteOptions MaxRedirects=10
> RewriteBase /
>
> RewriteRule ^packages/([^/]+)/([^/]+)$ /packages.php?title=
> $1&eventid=$2 [NC]
>
>
>
>
>
>
It's because in your HTML the URL's to the JS and images are relative.
Changing them to absolute should fix the problem
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
Isn't there a way to tell the Rewrite rule to skip anything found in a
js or images subfolder?
On Oct 25, 2009, at 12:26 PM, Ashley Sheridan wrote:
On Sun, 2009-10-25 at 11:04 -0400, Rob Gould wrote:
I'm trying to follow the RewriteRule docs to make it so that:
http://benchwarmersports.com/packages/super-bowl-xliv/1
can be entered into the web-browser, and it transforms into:
http://benchwarmersports.com/packages.php?title=super-bowl-xliv&eventid=1
The good news is that it does transform the url when I do this. The
bad news
is that it also attempts to transform all the links (including to JS
files
and images).
Can someone tell me what I'd need to modify to avoid this problem
with the
RewriteRule?
My .htaccess file presently looks like this:
Options +FollowSymlinks
RewriteEngine On
RewriteOptions MaxRedirects=10
RewriteBase /
RewriteRule ^packages/([^/]+)/([^/]+)$ /packages.php?title=
$1&eventid=$2 [NC]
It's because in your HTML the URL's to the JS and images are
relative. Changing them to absolute should fix the problem
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
On Sun, 2009-10-25 at 12:51 -0400, Rob Gould wrote:
> Isn't there a way to tell the Rewrite rule to skip anything found in a
> js or images subfolder?
>
>
> On Oct 25, 2009, at 12:26 PM, Ashley Sheridan wrote:
>
> > On Sun, 2009-10-25 at 11:04 -0400, Rob Gould wrote:
> >>
> >> I'm trying to follow the RewriteRule docs to make it so that:
> >>
> >> http://benchwarmersports.com/packages/super-bowl-xliv/1
> >>
> >> can be entered into the web-browser, and it transforms into:
> >>
> >> http://benchwarmersports.com/packages.php?title=super-bowl-xliv&eventid=1
> >>
> >>
> >> The good news is that it does transform the url when I do this. The
> >> bad news
> >> is that it also attempts to transform all the links (including to JS
> >> files
> >> and images).
> >>
> >> Can someone tell me what I'd need to modify to avoid this problem
> >> with the
> >> RewriteRule?
> >>
> >>
> >> My .htaccess file presently looks like this:
> >>
> >>
> >> Options +FollowSymlinks
> >> RewriteEngine On
> >> RewriteOptions MaxRedirects=10
> >> RewriteBase /
> >>
> >> RewriteRule ^packages/([^/]+)/([^/]+)$ /packages.php?title=
> >> $1&eventid=$2 [NC]
> >>
> >>
> >>
> >>
> >>
> >>
> >
> > It's because in your HTML the URL's to the JS and images are
> > relative. Changing them to absolute should fix the problem
> >
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
>
The rewrite rule isn't doing that though. What it is doing, is
converting the URL you give to something else on the server. The browser
still thinks it it the URL you gave though, so when it finds an image
going to "images/image1.jpg" it looks for that relative to the current
page it thinks it is displaying, irrespective of what the server is
doing.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
As Ashley said, its the wrong way to approach this problem.
I suggest you read about "base href". (<base href="http://....." /> )
it is a HTML tag.
On Sun, Oct 25, 2009 at 6:51 PM, Rob Gould <gould...@me.com> wrote:
> Isn't there a way to tell the Rewrite rule to skip anything found in a js
> or images subfolder?
>
>
>
> On Oct 25, 2009, at 12:26 PM, Ashley Sheridan wrote:
>
> On Sun, 2009-10-25 at 11:04 -0400, Rob Gould wrote:
>>
>>>
>>> I'm trying to follow the RewriteRule docs to make it so that:
>>>
>>> http://benchwarmersports.com/packages/super-bowl-xliv/1
>>>
>>> can be entered into the web-browser, and it transforms into:
>>>
>>> http://benchwarmersports.com/packages.php?title=super-bowl-xliv&eventid=1
>>>
>>>
>>> The good news is that it does transform the url when I do this. The
>>> bad news
>>> is that it also attempts to transform all the links (including to JS
>>> files
>>> and images).
>>>
>>> Can someone tell me what I'd need to modify to avoid this problem
>>> with the
>>> RewriteRule?
>>>
>>>
>>> My .htaccess file presently looks like this:
>>>
>>>
>>> Options +FollowSymlinks
>>> RewriteEngine On
>>> RewriteOptions MaxRedirects=10
>>> RewriteBase /
>>>
>>> RewriteRule ^packages/([^/]+)/([^/]+)$ /packages.php?title=
>>> $1&eventid=$2 [NC]
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>> It's because in your HTML the URL's to the JS and images are relative.
>> Changing them to absolute should fix the problem
>>
>> Thanks,
>> Ash
>> http://www.ashleysheridan.co.uk
>>
>>
>>
>
--
Use ROT26 for best security
--- End Message ---
--- Begin Message ---
<base will just complicate things... (its sure to solve your problems but
you have to type the relative path to your document root for every URI)
seems you are looking for
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#RewriteCond
--- End Message ---
--- Begin Message ---
Hi,
how to replace many spaces in any string of character with one space?
Regrads
--- End Message ---
--- Begin Message ---
2009/10/25 Jeffry Lunggot <jef...@rogon.com.my>:
> Hi,
>
> how to replace many spaces in any string of character with one space?
$str = preg_replace('/\s\s+/', ' ', $str);
--- End Message ---
--- Begin Message ---
On Sun, 2009-10-25 at 16:59 +0100, David Otton wrote:
> 2009/10/25 Jeffry Lunggot <jef...@rogon.com.my>:
> > Hi,
> >
> > how to replace many spaces in any string of character with one space?
>
> $str = preg_replace('/\s\s+/', ' ', $str);
>
$str = preg_replace('/\s+/', ' ', $str);
You don't need both space characters, as the + symbol matches one or
more, which is just what you want.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
Jeffry Lunggot wrote:
Hi,
how to replace many spaces in any string of character with one space?
Regrads
Be careful about the word "spaces" do you mean exactly " "; or white spaces
defined by "\s", which include spaces, tabs CRLFs.
If you want specifically spaces and not all white spaces, then use "\x20"
reg_replace("%\x20+%", " ", $str);//note the space between the quotes in the
replace.
If our string has CRLFs [i.e., newlines] then they will all will be reduced to
one. e.g., " \n\n\n" will end up as " \n" if you use \s.
Also take into account the pattern modifier "m" (PCRE_MULTILINE). It may apply
in your case.
--- End Message ---
--- Begin Message ---
Hi,
So I found out there are two bugs filed in bugs.php.net that are
related to this problem. The bugs are http://bugs.php.net/bug.php?id=49332and
http://bugs.php.net/bug.php?id=49267.
To anyone else that has the same issues as me, here is how to get
around the problem if you are trying to compile a freshly downloaded
copy of PHP 5.2.11 on Mac OS X 10.6.1.
1. First, open <php-5.2.11>/ext/iconv/iconv.c and edit line 197.
Lines 196-198 look like this originally:
---
#ifdef HAVE_LIBICONV
#define iconv libiconv
#endif
---
You need to change it to look like this:
---
#ifdef HAVE_LIBICONV
#define iconv iconv
#endif
---
2. When you run ./configure, prepend LIBS=-lresolv so the resulting
command is:
---
LIBS=-lresolv ./configure <...your options here...>
---
Now when you run make you should not get a compilation error and you
should be able to follow the rest of the instructions on http://www.php.net/manual/en/install.unix.apache2.php
to get your PHP 5.2.11 up and running.
Mari
On Oct 24, 2009, at 15:33, Mari Masuda wrote:
Hi,
I am setting up my Mac Book Pro running Mac OS X 10.6.1 as a
development environment for Drupal. I already successfully have
MySQL 5.1.40 and Apache 2.2.11 up and running. I tried to compile
PHP 5.2.11 in the following manner and keep getting an error. Any
help would be great!
1. Downloaded php-5.2.11.tar.gz from php.net. The MD5 checksum of
the downloaded file is the same as what is listed on php.net so I do
not think the file is corrupt.
2. Expanded php-5.2.11.tar.gz by double-clicking the file I
downloaded and moving the resulting folder (named "php-5.2.11") to
my desktop.
In terminal did the following (I am following the instructions in
the box labeled "Example #1 Installation Instructions (Apache 2
Shared Module Version)" at http://www.php.net/manual/en/install.unix.apache2.php
)
3. cd /Users/mari/Desktop/php-5.2.11
4. ./configure --prefix=/Applications/php --disable-short-tags --
with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/
mysql_config --with-apxs2=/Applications/apache/bin/apxs --enable-
mbstring --with-pdo-mysql=/usr/local/mysql
5. make
At this point, make does not complete and it exits with an error:
---start error---
Undefined symbols:
"_res_9_dn_expand", referenced from:
_zif_dns_get_mx in dns.o
"_res_9_search", referenced from:
_zif_dns_get_mx in dns.o
_zif_dns_check_record in dns.o
"_libiconv", referenced from:
__php_iconv_strlen in iconv.o
_php_iconv_string in iconv.o
_php_iconv_string in iconv.o
__php_iconv_strpos in iconv.o
__php_iconv_appendl in iconv.o
__php_iconv_appendl in iconv.o
_zif_iconv_substr in iconv.o
_zif_iconv_mime_encode in iconv.o
_zif_iconv_mime_encode in iconv.o
_zif_iconv_mime_encode in iconv.o
_zif_iconv_mime_encode in iconv.o
_zif_iconv_mime_encode in iconv.o
_zif_iconv_mime_encode in iconv.o
_php_iconv_stream_filter_append_bucket in iconv.o
_php_iconv_stream_filter_append_bucket in iconv.o
"_res_9_dn_skipname", referenced from:
_zif_dns_get_mx in dns.o
_zif_dns_get_mx in dns.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [libs/libphp5.bundle] Error 1
---end error---
To try to simplify things, I deleted the php-5.2.11 folder I created
in step 2 above and repeated steps 2 and 3. Then at this point I
only did ./configure by itself with no options, thinking that I
could try to see if any of my configuration options were causing the
issue. Alas, no, the problem still happens; the error is now this:
---start error---
Undefined symbols:
"_res_9_dn_expand", referenced from:
_zif_dns_get_mx in dns.o
"_res_9_search", referenced from:
_zif_dns_get_mx in dns.o
_zif_dns_check_record in dns.o
"_libiconv", referenced from:
__php_iconv_strlen in iconv.o
_php_iconv_string in iconv.o
_php_iconv_string in iconv.o
__php_iconv_strpos in iconv.o
__php_iconv_appendl in iconv.o
__php_iconv_appendl in iconv.o
_zif_iconv_substr in iconv.o
_zif_iconv_mime_encode in iconv.o
_zif_iconv_mime_encode in iconv.o
_zif_iconv_mime_encode in iconv.o
_zif_iconv_mime_encode in iconv.o
_zif_iconv_mime_encode in iconv.o
_zif_iconv_mime_encode in iconv.o
_php_iconv_stream_filter_append_bucket in iconv.o
_php_iconv_stream_filter_append_bucket in iconv.o
"_res_9_dn_skipname", referenced from:
_zif_dns_get_mx in dns.o
_zif_dns_get_mx in dns.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [sapi/cgi/php-cgi] Error 1
---end error---
What can I do to get around this problem and compile PHP? Thanks!
Mari
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
Sorry for the long post but this problem have plagued us for a few
months and we suspect that this is a OS-specific issue with
FreeBSD/PHP, AFAICS it has not been reported from the Linux camp. I'm
posting here in the hope that someone on this list might have a clue.
In brief, intermittently, the first character in a file name is lost
using the PHP "basename" function. Below is an excerpt from a Horde
webmail server's log that shows the error.
More reading can be found on the Horde list here:
http://marc.info/?l=horde&m=124653708009981&w=2
and here
http://marc.info/?l=horde&m=124683029904466&w=2
- Problem is present on both FreeBSD 6.4 and 7-STABLE
- We see it on two boxes so it's not limited to a single server
- It has occurred on all PHP versions since this year, approx from the
time of PHP 5.2.8 or 9
- It is intermittent - no real pattern
- It does not matter if we use the Horde cache or not, if we use a cache
via PHP or not, have tried a *lot* of configurations to no avail.
A more detailed log:
Obviously, we are looking for "memcache.php" but $basename sometimes
returns "emcache.php".
--------------
[21-Oct-2009 07:28:28] after basename d string(8) "memcache"
string(7) "emcache"
[21-Oct-2009 07:28:28] backtrace NULL
string(7) "emcache"
#0 Horde_Cache->factory(memcache, Array ([hostspec] => Array ([0] =>
localhost),[port] => Array ([0] => 11211),[weight] => Array
(),[persistent] => ,[compression] => ,[large_items] => 1,[enabled] =>
1)) called at [/usr/local/www/horde/lib/Horde/Cache.php:234]
#1 Horde_Cache->singleton(memcache, Array ([hostspec] => Array ([0] =>
localhost),[port] => Array ([0] => 11211),[weight] => Array
(),[persistent] => ,[compression] => ,[large_items] => 1,[enabled] =>
1)) called at [/usr/local/www/horde/lib/Horde/Perms/sql.php:57]
#2 Perms_sql->Perms_sql(Array ([username] => horde,[password] =>
<password>,[protocol] => unix,[database] => horde,[charset] =>
iso-8859-1,[splitread] => ,[ssl] => ,[phptype] => mysqli)) called at
[/usr/local/www/horde/lib/Horde/Perms.php:462]
#3 Perms->factory(sql, Array ([username] => horde,[password] =>
<password>,[protocol] => unix,[database] => horde,[charset] =>
iso-8859-1,[splitread] => ,[ssl] => ,[phptype] => mysqli)) called at
[/usr/local/www/horde/lib/Horde/Perms.php:496]
#4 Perms->singleton() called at
[/usr/local/www/horde/lib/Horde/Registry.php:278]
#5 Registry->Registry(0) called at
[/usr/local/www/horde/lib/Horde/Registry.php:139]
#6 Registry::singleton() called at
[/usr/local/www/horde/imp/lib/base.php:49]
#7 require_once(/usr/local/www/horde/imp/lib/base.php) called at
[/usr/local/www/horde/imp/redirect.php:89]
#8 require(/usr/local/www/horde/imp/redirect.php) called at
[/usr/local/www/horde/imp/index.php:26]
NULL
[21-Oct-2009 07:28:28] PHP Warning:
include_once(Horde/Cache/emcache.php) [<a
href='function.include-once'>function.include-once</a>]: failed to open
stream: No such file or directory in
/usr/local/www/horde/lib/Horde/Cache.php on line 194
[21-Oct-2009 07:28:28] PHP Warning: include_once() [<a
href='function.include'>function.include</a>]: Failed opening
'Horde/Cache/emcache.php' for inclusion
(include_path='/usr/local/www/horde/lib:.:/usr/local/share/pear') in
/usr/local/www/horde/lib/Horde/Cache.php on line 194
[21-Oct-2009 07:28:39] after basename d string(8) "memcache"
string(7) "emcache"
Thank you for reading...
--
per
--- End Message ---
--- Begin Message ---
I have a script which uploads csv data into a database. This works well
and has worked in every instance so far. However what I am noticing is
that today, even if I escape the data before putting it into mysql it
will not enter a line if it has a single quote, once I take out the
single quote it enters it into the database so I know it is the single
quote, is this an error or are single quotes not allowed in csv...?
--- End Message ---
--- Begin Message ---
Brian Hazelton wrote:
I have a script which uploads csv data into a database. This works
well and has worked in every instance so far. However what I am
noticing is that today, even if I escape the data before putting it
into mysql it will not enter a line if it has a single quote, once I
take out the single quote it enters it into the database so I know it
is the single quote, is this an error or are single quotes not allowed
in csv...?
I figured out part of the problem. The problem lies with one of my
functions for cleaning the data before putting it into the database. I
have a function, see below, that will clean the data to put into mysql
and work whether magic quotes is on or off. It is not working because I
echo the query and the part I need escaped is not being escaped. I try
mysql_real_escape_string and it is being escaped by that so I think the
problem is something with my function, if anyone can help that would be
appreciated.
function clean($str){
if(get_magic_quotes_gpc()){
stripslashes($str);
mysql_real_escape_string($str);
return $str;
}
else{
mysql_real_escape_string($str);
return $str;
}
}
$name = 'O'Leksy';
$cleaned_name = clean($name);
echo of $cleaned name = O'Leksy';
if mysql_real_escape_string is used it echoes O\'Leksy';
--- End Message ---
--- Begin Message ---
Brian Hazelton wrote:
Brian Hazelton wrote:
I have a script which uploads csv data into a database. This works
well and has worked in every instance so far. However what I am
noticing is that today, even if I escape the data before putting it
into mysql it will not enter a line if it has a single quote, once I
take out the single quote it enters it into the database so I know it
is the single quote, is this an error or are single quotes not
allowed in csv...?
I figured out part of the problem. The problem lies with one of my
functions for cleaning the data before putting it into the database. I
have a function, see below, that will clean the data to put into mysql
and work whether magic quotes is on or off. It is not working because
I echo the query and the part I need escaped is not being escaped. I
try mysql_real_escape_string and it is being escaped by that so I
think the problem is something with my function, if anyone can help
that would be appreciated.
function clean($str){
if(get_magic_quotes_gpc()){
stripslashes($str);
mysql_real_escape_string($str);
return $str;
}
else{
mysql_real_escape_string($str);
return $str;
}
}
$name = 'O'Leksy';
$cleaned_name = clean($name);
echo of $cleaned name = O'Leksy';
if mysql_real_escape_string is used it echoes O\'Leksy';
Sorry for all of the posts. I got it figured out, it was just me being
stupid. Since this data isnt coming from get, post or cookies then
calling this function will still work but no slashes are getting added
so when the stripslashes function is called it returns an error and will
not continue to work because it does not return the string on error.
--- End Message ---