php-general Digest 16 Aug 2003 20:20:29 -0000 Issue 2240

Topics (messages 159790 through 159804):

How to connect to DB
        159790 by: murugesan

Re: call function as variable
        159791 by: John W. Holmes
        159797 by: adam
        159798 by: David Otton
        159799 by: Michael Sims
        159800 by: adam
        159801 by: adam

better understanding of ereg_replace and other functions
        159792 by: Binay Agarwal
        159793 by: Boaz Yahav
        159803 by: Wouter van Vliet

preg_replace question
        159794 by: Jean-Christian IMbeault
        159795 by: jabber.raditha.com

imagecreatefromjpeg() problems
        159796 by: J-K

pop3 functions
        159802 by: andu

Re: Installing How-To
        159804 by: Jaap van Ganswijk

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 ---
Hello all,
        I have some existing php pages already. Now I want to change the DB
to point to another DB.

I have changed the include_path in php.ini file to point to /home/config
Also I changed the constant db_name defined in a file in
/home/config/con.php to point to new DB.

[snip]
<<<<<<<<<
include "con.php"
@mysql_pconnect(db_host,db_user,db_pass);
mysql_select_db (db_name) or die ("could not select db");
<<<<<<<<<<

<<<<<<<<<<<<<<<<<
//contents of con.php

<?php
  define('db_host','localhost');
  define('db_name','newdb') ;
  define('db_user','scott') ;
  define('db_pass','tiger') ;
  define('db_type','mysql') ;
 ?>


<<<<<<<<<<<<<<
Also I restarted the apache.
But it is still accessing the old DB.
What are all the changes that I have to make. other than these changes.

Regards,
Murugesan.


--- End Message ---
--- Begin Message --- adam wrote:
Hi!

I have folowing function which they are a member in a class.

function foo(){
something
}

function zoo(){
something else
}


and i have a array such:


$test = array(1=>foo,2=zoo);

and i want to call the fuction foo() and zoo something like;

$object->$test[1]();

Try:


{$object->$test[1]}();

--
---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

PHP|Architect: A magazine for PHP Professionals – www.phparch.com





--- End Message ---
--- Begin Message --- I got this error:

Parse error: parse error, unexpected '{' in .......

Cheers

John W. Holmes wrote:

adam wrote:

Hi!

I have folowing function which they are a member in a class.

function foo(){
something
}

function zoo(){
something else
}


and i have a array such:


$test = array(1=>foo,2=zoo);

and i want to call the fuction foo() and zoo something like;

$object->$test[1]();


Try:

{$object->$test[1]}();



--- End Message ---
--- Begin Message ---
On Sat, 16 Aug 2003 07:58:27 +0200, you wrote:

>I have folowing function which they are a member in a class.
>
>function foo(){
>something
>}
>
>function zoo(){
>something else
>}
>
>
>and i have a array such:
>
>$test = array(1=>foo,2=zoo);
>
>and i want to call the fuction foo() and zoo something like;
>
>$object->$test[1]();

The fact that you say "$object->$test" suggests that foo() and zoo() are
methods of a class? The following code snippet contains just about every
mechanism for calling a method of a class that there is. The one you'll
probably want is

        call_user_func (array ($C, 'B'), 'call 4');

<?

        /* Class A has method B */
        class A {
                function B ($s = "None") {
                        echo ("<p>input : $s</p>");
                }
        }

        /* $C is an instance of A */
        $C = new A ();

        /* $D is an array of strings */
        $D = array ('item 1', 'item 2', 'item 3', 'item 4');

        /* invoke A::B */
        A::B ('call 1');

        /* invoke $C->B */
        $C->B ('call 2');

        /* invoke A::B via call_user_func() */
        call_user_func (array ('A', 'B'), 'call 3');

        /* invoke $C->B via call_user_func() */
        call_user_func (array ($C, 'B'), 'call 4');

        /* invoke A::B via call_user_func_array() */
        call_user_func_array (array ('A', 'B'), array('call 5'));

        /* invoke $C->B via call_user_func_array() */
        call_user_func_array (array ($C, 'B'), array('call 6'));

        /* apply A::B to $D via array_walk() */
        array_walk ($D, array ('A', 'B'));

        /* apply $C->B to $D via array_walk() */
        array_walk ($D, array ($C, 'B'));

?>


--- End Message ---
--- Begin Message ---
On Sat, 16 Aug 2003 07:58:27 +0200, you wrote:

>$test = array(1=>foo,2=zoo);
>
>and i want to call the fuction foo() and zoo something like;
>
>$object->$test[1]();

I've never used this myself, but this should work:

call_user_func(&$object, $test[1]);

See:

http://www.php.net/manual/en/function.call-user-func.php

HTH

--- End Message ---
--- Begin Message ---
Tanks a lot!
this is exactly that i want!!

Cheers

Michael Sims wrote:

On Sat, 16 Aug 2003 07:58:27 +0200, you wrote:


$test = array(1=>foo,2=zoo);

and i want to call the fuction foo() and zoo something like;

$object->$test[1]();


I've never used this myself, but this should work:

call_user_func(&$object, $test[1]);

See:

http://www.php.net/manual/en/function.call-user-func.php

HTH


--- End Message ---
--- Begin Message ---
Tanks a lot!
This was exactly that i wanted!

Cheers

David Otton wrote:

On Sat, 16 Aug 2003 07:58:27 +0200, you wrote:


I have folowing function which they are a member in a class.

function foo(){
something
}

function zoo(){
something else
}


and i have a array such:


$test = array(1=>foo,2=zoo);

and i want to call the fuction foo() and zoo something like;

$object->$test[1]();


The fact that you say "$object->$test" suggests that foo() and zoo() are
methods of a class? The following code snippet contains just about every
mechanism for calling a method of a class that there is. The one you'll
probably want is

call_user_func (array ($C, 'B'), 'call 4');

<?

        /* Class A has method B */
        class A {
                function B ($s = "None") {
                        echo ("<p>input : $s</p>");
                }
        }

        /* $C is an instance of A */
        $C = new A ();

        /* $D is an array of strings */
        $D = array ('item 1', 'item 2', 'item 3', 'item 4');

        /* invoke A::B */
        A::B ('call 1');

        /* invoke $C->B */
        $C->B ('call 2');

        /* invoke A::B via call_user_func() */
        call_user_func (array ('A', 'B'), 'call 3');

        /* invoke $C->B via call_user_func() */
        call_user_func (array ($C, 'B'), 'call 4');

        /* invoke A::B via call_user_func_array() */
        call_user_func_array (array ('A', 'B'), array('call 5'));

        /* invoke $C->B via call_user_func_array() */
        call_user_func_array (array ($C, 'B'), array('call 6'));

        /* apply A::B to $D via array_walk() */
        array_walk ($D, array ('A', 'B'));

        /* apply $C->B to $D via array_walk() */
        array_walk ($D, array ($C, 'B'));

?>



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

Lot of places in manual i came across using "ereg_replace" or "ereg" is very resource 
intensive and hence its better to use "preg_replace" or "str_replace" or "strpos" if 
they do the jobs.

Now i am very curious to look at the source code (implementation) of these function so 
as to be able to decide the right choice for me. Can any one of you tell me where to 
find the source code of these functions. Do they require special privileges ??

Please help me out


Binay

--- End Message ---
--- Begin Message ---
Try these :

preg_replace
http://www.weberdev.com/AdvancedSearch.php?searchtype=example&sort=examp
le&example=preg_replace

str_replace
http://www.weberdev.com/AdvancedSearch.php?searchtype=example&sort=examp
le&example=str_replace

strpos
http://www.weberdev.com/AdvancedSearch.php?searchtype=example&sort=examp
le&example=strpos

Sincerely
 
berber
 
Visit http://www.weberdev.com/ Today!!!
To see where PHP might take you tomorrow.
Share your code : http://addexample.weberdev.com
Search for PHP Code from your browser http://toolbar.weberdev.com




-----Original Message-----
From: Binay Agarwal [mailto:[EMAIL PROTECTED] 
Sent: Saturday, August 16, 2003 2:39 AM
To: [EMAIL PROTECTED]
Subject: [PHP] better understanding of ereg_replace and other functions


Hi everybody,

Lot of places in manual i came across using "ereg_replace" or "ereg" is
very resource intensive and hence its better to use "preg_replace" or
"str_replace" or "strpos" if they do the jobs.

Now i am very curious to look at the source code (implementation) of
these function so as to be able to decide the right choice for me. Can
any one of you tell me where to find the source code of these functions.
Do they require special privileges ??

Please help me out


Binay

 


--- End Message ---
--- Begin Message ---
You can just download the source distribution of php, and on a linux
commandline do:

grep -inr preg_replace *

You'll find all occurances of preg_replace, including it's declaratin, which
I have copies below. It seems like it's being passed thru to another
function .. Which is also on the same file: ext/pcre/php_pcre.c (I've
searched a PHP5.0 sourcetree)

   1111 /* {{{ proto string preg_replace(mixed regex, mixed replace, mixed
subject [, int limit])
   1112    Perform Perl-style regular expression replacement. */
   1113 PHP_FUNCTION(preg_replace)
   1114 {
   1115     preg_replace_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
   1116 }
   1117 /* }}} */

Greetz,
Wouter

-----Oorspronkelijk bericht-----
Van: Binay Agarwal [mailto:[EMAIL PROTECTED]
Verzonden: zaterdag 16 augustus 2003 2:39
Aan: [EMAIL PROTECTED]
Onderwerp: [PHP] better understanding of ereg_replace and other
functions


Hi everybody,

Lot of places in manual i came across using "ereg_replace" or "ereg" is very
resource intensive and hence its better to use "preg_replace" or
"str_replace" or "strpos" if they do the jobs.

Now i am very curious to look at the source code (implementation) of these
function so as to be able to decide the right choice for me. Can any one of
you tell me where to find the source code of these functions. Do they
require special privileges ??

Please help me out


Binay



--- End Message ---
--- Begin Message --- I found this nice preg_replace function that replaces all occurrences of an HTML anchor (<a href=...) with a link to another PHP script that log the link and then sends the user on his merry way to the the appropriate page/site:

preg_replace(
  "#<a href=(\"|')http://([^\"']+)(\"|')#ime",
  '"<a href=\"/exit.php?url=".base64_encode(\'\\2\')."\""',
  $originalLink
);

I'd like to modify this expression so that it does the same thing but *only* if the link is not to a specific page. I.e. I would like to replace all links *unless* the link was to, for example, www.mydomain.com.

How can I achieve this with a regexp? I'm not very good at 'negative' regexp ...

Thanks,

Jean-Christian Imbeault


--- End Message ---
--- Begin Message --- Then use a simple strstr to first find out if the string does contain mydomain.com :-)

Jean-Christian IMbeault wrote:

I found this nice preg_replace function that replaces all occurrences of an HTML anchor (<a href=...) with a link to another PHP script that log the link and then sends the user on his merry way to the the appropriate page/site:

preg_replace(
  "#<a href=(\"|')http://([^\"']+)(\"|')#ime",
  '"<a href=\"/exit.php?url=".base64_encode(\'\\2\')."\""',
  $originalLink
);

I'd like to modify this expression so that it does the same thing but *only* if the link is not to a specific page. I.e. I would like to replace all links *unless* the link was to, for example, www.mydomain.com.

How can I achieve this with a regexp? I'm not very good at 'negative' regexp ...

Thanks,

Jean-Christian Imbeault




--

Raditha Dissanayake
-------------------------------------------------------------
http://www.radinks.com/sftp/
Lean and mean Secure FTP applet with Graphical User Inteface.
just 150 Kilo Bytes



--- End Message ---
--- Begin Message ---
      Hi!

      I've made a little script to make thumbnails which worked before the
summer, but now I get this errormessage:

      <b>Fatal error</b>:  Call to undefined function:
imagecreatefromjpeg() in
<b>/usr/local/others/www.stud.users/mark/gfx/create_tn.php</b> on line
<b>15</b>

      First I thought they had done something with the servers, because I
haven't touched the code. But I checked the GD-version and got this:
      GD Version: bundled (2.0.12 compatible)

      Shouldn't version 2.0.12 support imagecreatefromjpeg()?

      Is there any way I can get around this?

      In advance thanks!
      Best regards
      Jan-Kristian Markiewicz



--- End Message ---
--- Begin Message ---
Someone asked for the pop3 functions I put togather (lost your message),
please contact me off list, It works fine with my server but no
guaranties though there should be no problems.

I take the opportunity to express my 2 major problems I found with php
in the 2 months I've been using it. 
First is the naming of functions (whoever was the illiterate one who
invented them) definitely not meant to be remembered or to represent
what they actually do. It's a shame to have to fill our minds with such
garbage: strcasecmp, strchr, strcmp, strcoll, strcspn, stripos, stristr,
strspn, strstr, to take just a few. A programming language has already
its problems for not being natural, no need to make it even more so.
Second, it the array overkill.
Nevertheless, I love it.

-- 
Regards, Andu Novac

--- End Message ---
--- Begin Message ---
At 2003-08-15 15:12 -1000, Rodney Davis wrote:
>Does anyone know of a good howto on installing
>php w/ GD and phplib etc on a Redhat box?

I have just upgraded my (Mandrake) system by doing:
- Upgrading from Mandrake 9.0 to 9.1 using the CD's
  that came with the UK Linux Format magazine of
  june 2003:
  www.linuxformat.co.uk
- Then I installed the Apache Source version 2.0.45
  from the CD-ROM that came with PHP Magazine 4.2003
  www.php-mag.net
  and I compiled it, which went very smoothly
- Then I installed the PHP Source version 4.3.2
  from the same CD-ROM and compiled it. (Which
  takes more tinkering.)

The complete process took a while, especially because
I first tried to install from binaries, but it works
very well now, including a GD that supports true color
images etc.

I'm not saying that I think that Mandrake is currently
better than RedHat, but when I switched from Redhat
(5.2 or 6?) to Mandrake 7.2 (?) some years ago it's
installation process was even simpler than that of
RedHat (on which it is based).

In my experience it's a lot of work to upgrade all the
libraries by hand, because they are much too interdependent
and hard to locate on the WWW.

Some tips:
- Install Apache and PHP from source.
- Reboot your computer from time to time between installing
  things and changing .ini and .conf files, just restarting
  Apache is sometimes not enough it seems.
- Put a personal readme file in each directory, describing
  what you did to get things working. (This will help a lot
  next time.)

BTW. There is a separate mailing list about installing PHP.
You'd better ask there and look in it's archive etc.

Greetings,
Jaap


--- End Message ---

Reply via email to