php-general Digest 7 Mar 2006 08:34:13 -0000 Issue 4002
Topics (messages 231549 through 231577):
Re: Is this possible with php
231549 by: Robert Cummings
231550 by: João Cândido de Souza Neto
231551 by: tg-php.gryffyndevelopment.com
Re: Prepared statements
231552 by: Julius Hacker
Regexp matching in SQL
231553 by: Brian Anderson
231554 by: jblanchard.pocket.com
231559 by: Brian Anderson
231562 by: Chris
PHP4 with MYSQL5
231555 by: João Cândido de Souza Neto
231556 by: João Cândido de Souza Neto
231557 by: jblanchard.pocket.com
231563 by: Chris
PHP with FTP
231558 by: _-=MealstroM=-_
231564 by: Chris
231570 by: Chris
Re: create xml root-element with xmlns and xsd link (using DOM)
231560 by: Andreas Korthaus
Re: Mysql Rows
231561 by: Chris
Re: simplify DOM api
231565 by: Andreas Korthaus
Re: [PHP-DB] Re: PHP4 with MYSQL5
231566 by: Bastien Koert
Re: Mysql Rows [END of thread]
231567 by: tedd
Re: highlight_string()
231568 by: Chris
Generating License Codes for Distribution
231569 by: Bruce
OpenSSL error:0E06D06C:configuration file routines:func(109):reason(108) ??!
231571 by: Daevid Vincent
PHP Post to other Servers
231572 by: Robert Sandie
231573 by: Chris
231575 by: Robert Sandie
Mathematical CAPTCHA
231574 by: Louie Miranda
Re: Converting HTML to BBCode [medium]
231576 by: Rafael
Re: Converting HTML to BBCode [SOLVED]
231577 by: J_K9
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 ---
PHP can do this, but you'd need it set up on each of the client
computers and periodically run to check the temp folder and perform the
upload. That's what any other application that can do similar does.
Cheers,
Rob.
On Mon, 2006-03-06 at 15:30, João Cândido de Souza Neto wrote:
> PHP don't do this.
>
> The user must select a file to upload and then the PHP can work with this.
>
> PHP has no access to local files, think with me, how can PHP discover which
> machine in internet he has to access to get files.
>
> Mace Eliason wrote:
>
> > ------------------------------------------------------------------------
> > Hi,
> >
> > I really don't think this is possible from what I know of php, but I
> > thought I would as the experts.
> >
> > Is it possible to have php create directories and move files on a local
> > machine. I have created a web portal for a client and now they would
> > like it to upload files to an server, no a problem. But they would like
> > it to also move temp files on the users computer to new directories and
> > then upload the file to the server with no user interation other than
> > clicking go.
> >
> > I have thought of doing this in vb or c# but I have done very little
> > with these languages, and php just rocks.
> >
> > Thanks
> >
> > Scandog
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
--- End Message ---
--- Begin Message ---
Ok, but you're telling that the client will be doing upload to server. Not
the server doing a dounload from client. I was understood as a wrong way.
I'm sorry.
Robert Cummings wrote:
> PHP can do this, but you'd need it set up on each of the client
> computers and periodically run to check the temp folder and perform the
> upload. That's what any other application that can do similar does.
>
> Cheers,
> Rob.
>
> On Mon, 2006-03-06 at 15:30, João Cândido de Souza Neto wrote:
>> PHP don't do this.
>>
>> The user must select a file to upload and then the PHP can work with
>> this.
>>
>> PHP has no access to local files, think with me, how can PHP discover
>> which machine in internet he has to access to get files.
>>
>> Mace Eliason wrote:
>>
>> >
------------------------------------------------------------------------
>> > Hi,
>> >
>> > I really don't think this is possible from what I know of php, but I
>> > thought I would as the experts.
>> >
>> > Is it possible to have php create directories and move files on a local
>> > machine. I have created a web portal for a client and now they would
>> > like it to upload files to an server, no a problem. But they would like
>> > it to also move temp files on the users computer to new directories and
>> > then upload the file to the server with no user interation other than
>> > clicking go.
>> >
>> > I have thought of doing this in vb or c# but I have done very little
>> > with these languages, and php just rocks.
>> >
>> > Thanks
>> >
>> > Scandog
--- End Message ---
--- Begin Message ---
Yeah, you can't do the local computer file moving and all that with the same
script as your server side component, but if you'd rather not learn C# or
another language like that, but you're comfortable with PHP, I'd highly
recommend checking out Winbinder (http://www.winbinder.com). Assuming your
clients are all windows machines.
PHP is very powerful, it's just cumbersome to get a non-tech person to use a
typically shell oriented language to do things on the client's machine.
Winbinder provides a merging of PHP and Windows' native API. Takes a little
getting used to at first, but works great.
-TG
= = = Original message = = =
PHP can do this, but you'd need it set up on each of the client
computers and periodically run to check the temp folder and perform the
upload. That's what any other application that can do similar does.
Cheers,
Rob.
On Mon, 2006-03-06 at 15:30, Jo~o C~ndido de Souza Neto wrote:
> PHP don't do this.
>
> The user must select a file to upload and then the PHP can work with this.
>
> PHP has no access to local files, think with me, how can PHP discover which
> machine in internet he has to access to get files.
>
> Mace Eliason wrote:
>
> > ------------------------------------------------------------------------
> > Hi,
> >
> > I really don't think this is possible from what I know of php, but I
> > thought I would as the experts.
> >
> > Is it possible to have php create directories and move files on a local
> > machine. I have created a web portal for a client and now they would
> > like it to upload files to an server, no a problem. But they would like
> > it to also move temp files on the users computer to new directories and
> > then upload the file to the server with no user interation other than
> > clicking go.
> >
> > I have thought of doing this in vb or c# but I have done very little
> > with these languages, and php just rocks.
> >
> > Thanks
> >
> > Scandog
___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.
--- End Message ---
--- Begin Message ---
Curt Zirzow wrote:
>
> I assume your loop is something like:
> while(condition) {
> $auction_parts['id'] = 'some value';
> $auction_parts['name'] = 'some value';
> ...
> $insert->execute();
> }
>
Yes, thats it.
> My first guess would be, if not aleady done, initialize
> $auction_parts before you do your bind_param() with something like:
>
> $auction_parts = array('id' => null, 'name' => null, ...);
> $insert->bind_param("issdsis", $auction_house["id"], ...);
>
Unfortunately it helps nothing :-(
But I think also that it's something because of the declaration and
initalization of the variables because it works if I have the bind_param
in the loop after I gave the variables their values.
But to have the bind_param in the loop isn't the best solution I think.
--
Regards
Julius Hacker
http://www.julius-hacker.de
[EMAIL PROTECTED]
OpenPGP-Key-ID: 0x4B4A486E
--- End Message ---
--- Begin Message ---
I am trying to simplify an SQL query that is pretty much like below:
$sql = "SELECT * FROM table WHERE keyword RLIKE '$expression1' OR
keyword RLIKE '$expression2' ";
The different terms '$expression1' and '$expression1' come from an array.
Is there any way to within one regular expression to say either term1 or
term 2? Something like this where the OR condition would be basically
built into the regular expression:
$sql = "SELECT * FROM table WHERE keyword RLIKE '$expression'"; // the
$expression would have to signify either a or b.
Does that make sense?
--- End Message ---
--- Begin Message ---
[snip]
I am trying to simplify an SQL query that is pretty much like below:
$sql = "SELECT * FROM table WHERE keyword RLIKE '$expression1' OR
keyword RLIKE '$expression2' ";
The different terms '$expression1' and '$expression1' come from an
array.
Is there any way to within one regular expression to say either term1 or
term 2? Something like this where the OR condition would be basically
built into the regular expression:
$sql = "SELECT * FROM table WHERE keyword RLIKE '$expression'"; // the
$expression would have to signify either a or b.
Does that make sense?
[/snip]
Kinda'. If you asked on a SQL board they would say do this;
SELECT * FROM table WHERE keyword IN ($expression1, $expression2)
IN is the shorthand for multiple OR conditions.
--- End Message ---
--- Begin Message ---
"IN ( exp1, exp2)" didn't seem to work for me. I've seen that used
before for including a subquery, but somehow it didn't like the comma
separated list.
I think this below is doing it for me.
$separated = implode("|", (explode(" ",
(AddSlashes($_REQUEST['terms'])))));
if($_REQUEST['c'] == "and"){
$conditional = 'AND';
}else{
$conditional = 'OR';
}
$delim = " WHERE Keyword REGEXP '$separated' $conditional
ItemDescription REGEXP '$separated'";
I'm still curious about the IN() keyword and how it works.
-Brian
[EMAIL PROTECTED] wrote:
[snip]
I am trying to simplify an SQL query that is pretty much like below:
$sql = "SELECT * FROM table WHERE keyword RLIKE '$expression1' OR
keyword RLIKE '$expression2' ";
The different terms '$expression1' and '$expression1' come from an
array.
Is there any way to within one regular expression to say either term1 or
term 2? Something like this where the OR condition would be basically
built into the regular expression:
$sql = "SELECT * FROM table WHERE keyword RLIKE '$expression'"; // the
$expression would have to signify either a or b.
Does that make sense?
[/snip]
Kinda'. If you asked on a SQL board they would say do this;
SELECT * FROM table WHERE keyword IN ($expression1, $expression2)
IN is the shorthand for multiple OR conditions.
--- End Message ---
--- Begin Message ---
Brian Anderson wrote:
"IN ( exp1, exp2)" didn't seem to work for me. I've seen that used
before for including a subquery, but somehow it didn't like the comma
separated list.
I think this below is doing it for me.
$separated = implode("|", (explode(" ",
(AddSlashes($_REQUEST['terms'])))));
if($_REQUEST['c'] == "and"){
$conditional = 'AND';
}else{
$conditional = 'OR';
}
$delim = " WHERE Keyword REGEXP '$separated' $conditional
ItemDescription REGEXP '$separated'";
I'm still curious about the IN() keyword and how it works.
in() is good for id's:
select * from table where categoryid in (1,2,3,4,5);
it's basically expanded to an or:
select * from table where categoryid=1 or categoryid=2 or categoryid=3
or categoryid=4 or categoryid=5;
[EMAIL PROTECTED] wrote:
[snip]
I am trying to simplify an SQL query that is pretty much like below:
$sql = "SELECT * FROM table WHERE keyword RLIKE '$expression1' OR
keyword RLIKE '$expression2' ";
The different terms '$expression1' and '$expression1' come from an
array.
Is there any way to within one regular expression to say either term1 or
term 2? Something like this where the OR condition would be basically
built into the regular expression:
$sql = "SELECT * FROM table WHERE keyword RLIKE '$expression'"; // the
$expression would have to signify either a or b.
Does that make sense?
[/snip]
Kinda'. If you asked on a SQL board they would say do this;
SELECT * FROM table WHERE keyword IN ($expression1, $expression2)
IN is the shorthand for multiple OR conditions.
--
Postgresql & php tutorials
http://www.designmagick.com/
--- End Message ---
--- Begin Message ---
Hello everyone.
I'm trying to use my php4 conecting to a mysql5 server, and then executing
some command lines to create a stored procedure but it's not working.
When a tried to execute "delimiter |", my php gets de follow error:
You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near 'delimiter |' at
line 1
If I connect to server as local and try to execute the above command, it
works fine.
Could anyone help me about this? I'll be pleased by any tips.
Thanks.
--- End Message ---
--- Begin Message ---
I receive aa answer by e-mail in order this telling me that i must upgrade
my php4 to php5.
It means that a php4 server don't works fine with mysql5 server?
João Cândido de Souza Neto wrote:
> Hello everyone.
>
> I'm trying to use my php4 conecting to a mysql5 server, and then executing
> some command lines to create a stored procedure but it's not working.
>
> When a tried to execute "delimiter |", my php gets de follow error:
>
> You have an error in your SQL syntax; check the manual that corresponds to
> your MySQL server version for the right syntax to use near 'delimiter |'
> at line 1
>
> If I connect to server as local and try to execute the above command, it
> works fine.
>
> Could anyone help me about this? I'll be pleased by any tips.
>
> Thanks.
--- End Message ---
--- Begin Message ---
[snip]
I receive aa answer by e-mail in order this telling me that i must upgrade
my php4 to php5.
It means that a php4 server don't works fine with mysql5 server?
[/snip]
http://www.php.net/mysqli is designed to work with versions of MySQL 4.1.n and
above. It requires PHP5
--- End Message ---
--- Begin Message ---
João Cândido de Souza Neto wrote:
I receive aa answer by e-mail in order this telling me that i must upgrade
my php4 to php5.
It means that a php4 server don't works fine with mysql5 server?
João Cândido de Souza Neto wrote:
Hello everyone.
I'm trying to use my php4 conecting to a mysql5 server, and then executing
some command lines to create a stored procedure but it's not working.
When a tried to execute "delimiter |", my php gets de follow error:
You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near 'delimiter |'
at line 1
If I connect to server as local and try to execute the above command, it
works fine.
Could anyone help me about this? I'll be pleased by any tips.
Thanks.
Depends on your query.
Post your exact query and we'll see if we can help.
--
Postgresql & php tutorials
http://www.designmagick.com/
--- End Message ---
--- Begin Message ---
Hello php-general,
Hi. I ve got some trabl with this commands
ftp_pwd() and ftp_chdir()
They work correctly with some ftp servers,
but i ve got some problems with warftp server.
This server doesn't recognize them.
Here is my function
function engine($conn_id,$host_id)
{
if($conn_id==NULL){return NULL;}
$d_list=d_list($conn_id);
for($i=0;$i<count($d_list[1]);$i++)
{
if($d_list[0][$i]=='d')
{
ftp_chdir($conn_id, $d_list[1][$i]);
if(ftp_pwd($conn_id)!='/'){$path=ftp_pwd($conn_id)."/".engine($conn_id,$host_id);}
else {$path=ftp_pwd($conn_id).engine($conn_id,$host_id);};
engine_reg($path,$host_id);
ftp_cdup($conn_id);
}
else {
if(ftp_pwd($conn_id)!='/'){$path=ftp_pwd($conn_id)."/".$d_list[1][$i];}
else {$path=ftp_pwd($conn_id).$d_list[1][$i];}
engine_reg($path,$host_id);
};
// else echo ftp_pwd($conn_id)."/".$d_list[1][$i]."<br>";
}
return 1;
}
--
Best regards,
_-=MealstroM=-_ mailto:[EMAIL PROTECTED]
--- End Message ---
--- Begin Message ---
_-=MealstroM=-_ wrote:
Hello php-general,
Hi. I ve got some trabl with this commands
ftp_pwd() and ftp_chdir()
They work correctly with some ftp servers,
but i ve got some problems with warftp server.
This server doesn't recognize them.
If the server doesn't recognise them we can't do much.
If you can put together a small self-contained example you could post a
bug report but I think they'll tell you it's not their problem, it's the
ftp server's problem.
--
Postgresql & php tutorials
http://www.designmagick.com/
--- End Message ---
--- Begin Message ---
_-=MealstroM=-_ wrote:
Hello Chris,
Tuesday, March 7, 2006, 1:36:54 AM, you wrote:
_-=MealstroM=-_ wrote:
Hello php-general,
Hi. I ve got some trabl with this commands
ftp_pwd() and ftp_chdir()
They work correctly with some ftp servers,
but i ve got some problems with warftp server.
This server doesn't recognize them.
If the server doesn't recognise them we can't do much.
If you can put together a small self-contained example you could post a
bug report but I think they'll tell you it's not their problem, it's the
ftp server's problem.
I ve got the advise to make some function like this:
int ftp_login(int ftp_stream, string username, string password);
//where username and password may be different
He says that's my answer, and the problem is related with
some browser's options or something like this. But i don't really
know what to do.
PS: sorry for my English.
Please post to the list as well - others may be able to help you where I
can't.
Basically you have to log in to the ftp account.
See http://www.php.net/ftp_login for examples on how to do it.
--
Postgresql & php tutorials
http://www.designmagick.com/
--- End Message ---
--- Begin Message ---
Rob wrote:
That's how namespaced attributes, which is nothing more than you are
creating, are supposed to be created in DOM.
OK, thank you!
best regards
Andreas
--- End Message ---
--- Begin Message ---
Barry:
I realize that relational dB's are out if one does this -- and -- I
fully understand why.
That's the reason when I started this thread I made it clear that I was
NOT talking about a relational dB but rather a simple flat file.
What I find interesting in all of this exchange -- however -- is that
everyone agree's renumbering the "id" of a dB is something you don't do,
but no one can come up with a concrete (other than relational) reason why.
I haven't finished reading this thread but here's why.
It's because those id's could be used as foreign keys.
I'll set up an example:
create table author (authorid int, authorname varchar(200));
insert into author(authorid, authorname) values(1, 'Chris 1');
insert into author(authorid, authorname) values(2, 'Chris 2');
create table news(newsid int, newstitle varchar(200), authorid int);
insert into news(newsid, newstitle, authorid) values (1, 'News by first
author', 1);
insert into news(newsid, newstitle, authorid) values (1, 'News by second
author', 2);
If you delete author '1' and then renumber, you have to go through every
other table in the database to see if anything relates to authorid '1'
and update it.
Extremely time consuming and extremely error prone.
--
Postgresql & php tutorials
http://www.designmagick.com/
--- End Message ---
--- Begin Message ---
Rob Richards wrote:
You can also look at using xmlwriter, when creating serialized trees,
that automatically does escaping for you.
Hm, AFAIK latest xmlwriter versions provide an OO API. Do you know about
any documentation for it?
The only code I've seen so far is:
http://cvs.php.net/viewcvs.cgi/pecl/xmlwriter/examples/xmlwriter_oo.php?view=markup&rev=1.1.2.2
And that's not too much (but promising) ;-) Or do you know about some
more complex examples?
Btw. I need to validate my created documents against an XML schema, I
doubt this is possible with xmlwriter.
Best regards
Andreas
--- End Message ---
--- Begin Message ---
it does, you need the updated mysql library that comes with the php 5 files
(libmysql.dll for windows)
bastien
From: João Cândido de Souza Neto <[EMAIL PROTECTED]>
To: [email protected],[email protected]
Subject: [PHP-DB] Re: PHP4 with MYSQL5
Date: Mon, 06 Mar 2006 18:38:56 -0300
I receive aa answer by e-mail in order this telling me that i must upgrade
my php4 to php5.
It means that a php4 server don't works fine with mysql5 server?
João Cândido de Souza Neto wrote:
> Hello everyone.
>
> I'm trying to use my php4 conecting to a mysql5 server, and then
executing
> some command lines to create a stored procedure but it's not working.
>
> When a tried to execute "delimiter |", my php gets de follow error:
>
> You have an error in your SQL syntax; check the manual that corresponds
to
> your MySQL server version for the right syntax to use near 'delimiter |'
> at line 1
>
> If I connect to server as local and try to execute the above command, it
> works fine.
>
> Could anyone help me about this? I'll be pleased by any tips.
>
> Thanks.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
Hi gang:
<?php
echo str_repeat("Okay, I give up! ", 100);
?>
Miles said:
Why are we still chasing this thread?
No need to pursue this thread anymore -- I'll just address the
statements put to me.
Why does he even have to see gaps? Just present the info, unless he
wants to see the ID.
Miles, I think that's the best solution I've heard thus far -- thanks.
---
JM said:
If you don't care that a given record may have a different, unpredictable
record number each time its queried, and if you're sure no one is going to
inherit this application and be stymied by your unorthodox approach, and if
you know that in the future you will not need to access this data by a
static record number, it doesn't matter. Otherwise, my advice would be to
add a timestamp column and sort by that instead.
LOL -- I think you drove your point home -- thanks.
----
Anthony Ettinger said:
I think the main reason is fora more extensible design. Sure, you may
only have the 1 table now, and think you never will enhance your
functionality...but as soon as you do comes up with a new scenario,
you'll have to change the current behavior...easier to plan for that
ahead of time. Technically, it works the way you want it...there's no
right or wrong way, just degrees of flexibility, and it so happens
this method seems inflexible from what I gather.
Very good -- thanks.
---
Paul said:
It's simply -- concretely -- inefficient & inelegant to modify on
average half the records in a database simply in order to delete one
record, when queries give us fast, simple, READ-ONLY methods for
enumerating existing data.
Okay, I got the idea -- thank you.
You guys are great -- thanks for putting up with me. As Daniel Boone
once wrote: "I have never been lost, but I will admit to being
confused for several weeks."
tedd
--
--------------------------------------------------------------------------------
http://sperling.com
--- End Message ---
--- Begin Message ---
Weber Sites LTD wrote:
I was afraid of that...
I need to do HTML manipulations on the text that is outside the <??>.
After I run highlight_string the original text is messed up.
If I run the manipulations before then they will look like HTML
And not act as HTML...
Any ideas?
You could get the php from your page, highlight it and replace it back in:
preg_replace('%<?(.*)?>%s', 'highlight_string(${1})', $content);
don't know if that will work straight out for you but that should give
you an idea on how to proceed.
Or you could temporarily remove them, do whatever then replace it back in:
$placeholders = array();
while(preg_match('%<?(.*)?>%s', $content, $matches)) {
$size = sizeof($placeholders);
$placeholders[$size] = $matches[1];
$content = str_replace($matches[0], '%%PLACEHOLDER['.$size.']%%',
$content);
}
... other processing here.
foreach($placeholders as $i => $text) {
$content = str_replace('%%PLACEHOLDER['.$i.']%%',
highlight_string($text), $content);
}
-----Original Message-----
From: chris smith [mailto:[EMAIL PROTECTED]
Sent: Monday, March 06, 2006 11:59 AM
To: Weber Sites LTD
Cc: [email protected]
Subject: Re: [PHP] highlight_string()
On 3/6/06, Weber Sites LTD <[EMAIL PROTECTED]> wrote:
The only way I could work around this was to put empty <??> at the
Beginning of the text and now highlight_string() highlights only what
Is inside <? ?>
You can see an example of the problematic text in the example Area of
this page : http://www.weberdev.com/get_example-4345.html
Notice the empty <? ?> at the beginning of the example.
Without them, all of the example, including the text and HTML Part
will be painted by highlight_string().
Is this a bug?
No. It will highlight html as well.
You can give the illusion of it not highlighting the html by using:
ini_set('highlight.html', '#000000');
--
Postgresql & php tutorials
http://www.designmagick.com/
--
Postgresql & php tutorials
http://www.designmagick.com/
--- End Message ---
--- Begin Message ---
I am looking for some PHP code that will allow me to do something like take
a string name, an expiration date, and a 16-byte key and generate an 8-byte
license code in the form of
FFFF-FFFF-FFFF-FFFF
I have some Windows code that I've used for years, and I successfully ported
it to PHP, only to find out that different systems treat integer overflows
differently.
--Bruce
--- End Message ---
--- Begin Message ---
I copied and pasted the example found here:
http://www.php.net/openssl_csr_new
And this one too:
http://www.php.net/manual/en/function.openssl-pkey-new.php
And I get the output that looks like valid 'gibberish' for all three (CSR,
Cert, PK), except what concerns me is that I get fifteen of the same
(completely useless and unhelpful) errors too?!
while (($e = openssl_error_string()) !== false)
echo $e . "<BR>\n";
error:0E06D06C:configuration file routines:func(109):reason(108)
... Snip the other 13 of these ...
error:0E06D06C:configuration file routines:func(109):reason(108)
Google doesn't return a single hit for that error message!?
I tried this "trick" to 'clear' the error buffer prior to my cert
generation,
but no luck.
http://www.php.net/manual/en/function.openssl-error-string.php
I'm using PHP v5.0.3 on linux.
This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.0.3, Copyright (c) 1998-2004 Zend Technologies
with Zend Extension Manager v1.0.9, Copyright (c) 2003-2005, by Zend
Technologies
with Zend Optimizer v2.6.0, Copyright (c) 1998-2005, by Zend
Technologies
# openssl version
OpenSSL 0.9.7d 17 Mar 2004
--- End Message ---
--- Begin Message ---
Want to load balance a server and send image uploads to a different box with
PHP installed. What would the correct method to authenticate on the second
machine and send without ruining user experience by sending them to a second
page?
Initial thought was to keep the box address inside of the box address?
- Rob
--- End Message ---
--- Begin Message ---
Robert Sandie wrote:
Want to load balance a server and send image uploads to a different box with
PHP installed. What would the correct method to authenticate on the second
machine and send without ruining user experience by sending them to a second
page?
For what purpose are you sending the uploads to a different box?
You could always keep the image in the database, then you don't need to
worry about which server has the image and which doesn't, always get it
from the db.
--
Postgresql & php tutorials
http://www.designmagick.com/
--- End Message ---
--- Begin Message ---
> For what purpose are you sending the uploads to a different box?
There will also be Video uploads as well so I had to nix the database idea.
Am running a media server as well of this box so there is considerable
processing already going on. Now I may be looking at this from the wrong
perspective and was hoping to gain some insight into this methodology.
- Rob
--- End Message ---
--- Begin Message ---
Is there a pear package or class for PHP?
--
Louie Miranda ([EMAIL PROTECTED])
http://www.axishift.com
//JSM-W
--- End Message ---
--- Begin Message ---
First of all, the back-slashes added before a " character is probably
because of the gpc_magic_quotes directive in PHP, wich tries to "escape"
the quotes (pretty stupid, if you ask me), so you must have to use
strip_slashes() on the string you received, e.g:
$text = '';
if ( isset($_POST['text']) ) {
$text = $_POST['text'];
if ( get_magic_quotes_gpc() ) {
$text = stripslashes($text);
}
}
Now, what you're trying to do is definetely not something "basic",
since you want to replace some non-fixed strings that can either be in
lower or uppercase (and without changing the case of the rest of the
text), so basicaly what you have are patterns (some kind of 'rules' that
shall be followed by the tags)
By your code I can tell you've already try a little the hard way to
solve this issue, although it would be quite more laborious than that
because you would have to search the string almost char-by-char (in a
figurative way, but pretty much what PHP would be doing) for all the
tags you want to replace, and possibly be working with two strings: one
for the original text and other with a lowercase version of it (since
you cannot search in a case-insensitive way --only in PHP5)
Anyway, the medium/advanced way (IMHO) would be to use regular
expressions. These are quite useful, but also rather cryptic, even for
advanced users --sometimes it's easier to come up with a new one rather
than understanding what already exists :p
The function I've test with your test HTML-code is this one:
/**
* Performes BBCode conversion for some simple HTML elements
*
* @staticvar string $str_http_valid
* @staticvar array $arr_replace
* @param string $string
* @return string
* @since Mon Mar 06 23:44:40 CST 2006
* @author rsalazar
*/
function to_bbcode( $string ) {
static $str_http_valid = '-:\/a-z.0-9_%+';
$arr_replace = array(
"/<a\s+.*?(?<=\b)href=(?(?=['\"])(?:(['\"])(.*?)\\1)|([$str_http_valid]*)).*?>(.+?)<\/a>/Xis"
=> '[link=\\2\\3]\\4[/link]',
"/<img\s+.*?(?<=\b)src=(?(?=['\"])(?:(['\"])(.*?)\\1)|([$str_http_valid]*)).*?\/?>/Xis"
=> '[img]\\2\\3[/img]',
'/<(\/)?(strong|em)>/Xise' => '( strcasecmp("em", "\\2") ?
"[\\1b]" : "[\\1i]" )',
'/<(\/?(?:b|i|u))>/Xis' => '[\\1]',
'/<(\/)?[ou]l>/Xis' => '[\\1list]',
'/<(\/)?li>/Xise' => '( "\\1" == "" ? "[*]" : "" )',
);
$string = preg_replace(array_keys($arr_replace),
array_values($arr_replace),
$string);
return $string;
}
As I mentiones before, keep in mind that reg-exp can be rather cryptic
sometimes. Also, this is the raw code, it should be optimized but I'm
feeling really lazy right now, so it should have to wait for a better
ocasion.
It's up to you to decide wheter you'll use this function or not, what I
would recommend you is not to forget about regexp and give them a try
later (when you're more familiar with PHP), and I would also recommend
you to use PREG family rather than EGREP.
J_K9 wrote:
Hi,
I'm trying to code a PHP app to convert my inputted HTML code (into a
textarea) into BBCode, for use on a forum. I have tried to code it,
but have had little success so far. Here is the code I wrote (sorry,
I'm still learning):
-------CODE-------
<html>
<head>
<title>Convert from HTML to BBCode</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Body: <br /><textarea name="text"></textarea><br /><br />
<input type="submit" name="submit" value="Submit me!" />
</form>
<?php
$text = $_REQUEST['text'];
echo '<br /><br />';
// Declare HTML tags to find, and BBCode tags to replace them with
$linkStartFind = '<a href="';
$linkStartReplace = '[url=';
$linkEndFind = '</a>';
$linkEndReplace = '[/url]';
$italicStartFind = '<em>';
$italicStartReplace = '[i]';
$italicEndFind = '</em>';
$italicEndReplace = '[/i]';
$boldStartFind = '<strong>';
$boldStartReplace = '[b]';
$boldEndFind = '</strong>';
$boldEndReplace = '[/b]';
$imgStartFind = '<img src="';
$imgStartReplace = '[img]';
$imgEndFind = ' border="0" />';
$imgEndReplace = '[/img]';
$OLBeginFind = '<ol>';
$OLBeginReplace = '';
$OLFinishFind = '</ol>';
$OLFinishReplace = '';
$listStartFind = '<li>';
$listStartReplace = '[list]';
$listEndFind = '</li>';
$listEndReplace = '[/list]';
// Replace.
$text = str_replace($linkStartFind, $linkStartReplace, $text);
$text = str_replace($linkEndFind, $linkEndReplace, $text);
$text = str_replace($italicStartFind, $italicStartReplace, $text);
$text = str_replace($italicEndFind, $italicEndReplace, $text);
$text = str_replace($boldStartFind, $boldEndReplace, $text);
$text = str_replace($boldEndFind, $boldEndReplace, $text);
$text = str_replace($imgStartFind, $imgStartReplace, $text);
$text = str_replace($imgEndFind, $imgEndReplace, $text);
$text = str_replace($OLStartFind, $OLStartReplace, $text);
$text = str_replace($OLEndFind, $OLEndReplace, $text);
$text = str_replace($listStartFind, $listStartReplace, $text);
$text = str_replace($listEndFind, $listEndReplace, $text);
echo '<textarea name="output">' . "$text" . '</textarea>';
?>
</body>
</html>
-------/CODE-------
Now, most of this doesn't work. Here is the test code I put into the
first textarea:
-------TESTCODE-------
<strong>Testing bold code</strong>
<em>Testing italics</em>
<a href="http://link.com">Testing link</a>
<img src="http://image.com/img.jpg" border="0" />
<img src="http://image.com/img2.jpg" style="padding-right: 5px;"
border="0" />
-------/TESTCODE-------
And here's what I got out:
-------RESULT-------
[/b]Testing bold code[/b]
[i]Testing italics[/i]
<a href=\"http://link.com\">Testing link[/url]
<img src=\"http://image.com/img.jpg\" border=\"0\" />
<img src=\"http://image.com/img2.jpg\" style=\"padding-right: 5px;\"
border=\"0\" />
-------/RESULT-------
As you can see, the bold, italic, and ending hyperlink tag
replacements worked, but the rest didn't. Backslashes have been added
where there are "", and if there were anything between an img
tag's 'src="{image}"' and ' border="0" />' that wouldn't be removed,
and therefore provide me with a faulty link.
Just to clarify the BBCode tags, they are:
[url=http://link.com]Click this link[/url]
[img]http://imagesite.com/image.jpg[/img]
[b]_BOLD_[/b]
[i]italicised[/i]
[u]underlined[/i]
I would really like to get this working, as it'll not only help me
improve my PHP skills but also aid my tutorial conversions - it takes
ages to do this by hand ;)
Any help would be appreciated. Thanks in advance,
--
Atentamente,
J. Rafael Salazar Magaña
Innox - Innovación Inteligente
Tel: +52 (33) 3615 5348 ext. 205 / 01 800 2-SOFTWARE
http://www.innox.com.mx
--- End Message ---
--- Begin Message ---
Hi,
Thank you for that - although I do have to admit that I don't
understand a single bit of the reg-exp part. :)
It is now working flawlessly! Here is the final code I used:
-------CODE-------
<!-- Note - input textarea and submit button already coded here in
XHTML -->
<?php
$text = '';
if ( isset($_POST['text']) ) {
$text = $_POST['text'];
if ( get_magic_quotes_gpc() ) {
$text = $_POST['text'];
$text = stripslashes($text);
}
}
echo '<br /><br />';
/**
* Performes BBCode conversion for some simple HTML elements
*
* @staticvar string $str_http_valid
* @staticvar array $arr_replace
* @param string $string
* @return string
* @since Mon Mar 06 23:44:40 CST 2006
* @author rsalazar
*/
function to_bbcode( $string ) {
static $str_http_valid = '-:\/a-z.0-9_%+';
$arr_replace = array(
"/<a\s+.*?(?<=\b)href=(?(?=['\"])(?:(['\"])(.*?)\\1)|([$str_http_valid]
*)).*?>(.+?)<\/a>/Xis"
=> '[link=\\2\\3]\\4[/link]',
"/<img\s+.*?(?<=\b)src=(?(?=['\"])(?:(['\"])(.*?)\\1)|
([$str_http_valid]*)).*?\/?>/Xis"
=> '[img]\\2\\3[/img]',
'/<(\/)?(strong|em)>/Xise' => '( strcasecmp("em", "\\2") ?
"[\\1b]" : "[\\1i]" )',
'/<(\/?(?:b|i|u))>/Xis' => '[\\1]',
'/<(\/)?[ou]l>/Xis' => '[\\1list]',
'/<(\/)?li>/Xise' => '( "\\1" == "" ? "[*]" : "" )',
);
$string = preg_replace(array_keys($arr_replace),
array_values($arr_replace),
$string);
return $string;
}
$text = to_bbcode($text);
echo '<textarea name="output">' . "$text" . '</textarea>';
?>
-------/CODE-------
Thank you very much for your help! I hope I get onto reg-exp and PREG
stuff soon so that someday I might be able to understand that code.. :D
Cheers,
J_K9
> First of all, the back-slashes added before a " character is
probably
> because of the gpc_magic_quotes directive in PHP, wich tries
to "escape"
> the quotes (pretty stupid, if you ask me), so you must have to use
> strip_slashes() on the string you received, e.g:
> $text = '';
> if ( isset($_POST['text']) ) {
> $text = $_POST['text'];
> if ( get_magic_quotes_gpc() ) {
> $text = stripslashes($text);
> }
> }
>
> Now, what you're trying to do is definetely not
something "basic",
> since you want to replace some non-fixed strings that can either be
in
> lower or uppercase (and without changing the case of the rest of the
> text), so basicaly what you have are patterns (some kind of 'rules'
that
> shall be followed by the tags)
>
> By your code I can tell you've already try a little the hard
way to
> solve this issue, although it would be quite more laborious than
that
> because you would have to search the string almost char-by-char (in
a
> figurative way, but pretty much what PHP would be doing) for all the
> tags you want to replace, and possibly be working with two strings:
one
> for the original text and other with a lowercase version of it
(since
> you cannot search in a case-insensitive way --only in PHP5)
>
> Anyway, the medium/advanced way (IMHO) would be to use regular
> expressions. These are quite useful, but also rather cryptic, even
for
> advanced users --sometimes it's easier to come up with a new one
rather
> than understanding what already exists :p
>
> The function I've test with your test HTML-code is this one:
> /**
> * Performes BBCode conversion for some simple HTML elements
> *
> * @staticvar string $str_http_valid
> * @staticvar array $arr_replace
> * @param string $string
> * @return string
> * @since Mon Mar 06 23:44:40 CST 2006
> * @author rsalazar
> */
> function to_bbcode( $string ) {
> static $str_http_valid = '-:\/a-z.0-9_%+';
> $arr_replace = array(
>
> "/<a\s+.*?(?<=\b)href=(?(?=['\"])(?:(['\"])(.*?)\\1)|
([$str_http_valid]*)).*?>(.+?)<\/a>/Xis"
> => '[link=\\2\\3]\\4[/link]',
>
> "/<img\s+.*?(?<=\b)src=(?(?=['\"])(?:(['\"])(.*?)\\1)|
([$str_http_valid]*)).*?\/?>/Xis"
> => '[img]\\2\\3[/img]',
> '/<(\/)?(strong|em)>/Xise' => '( strcasecmp
("em", "\\2") ?
> "[\\1b]" : "[\\1i]" )',
> '/<(\/?(?:b|i|u))>/Xis' => '[\\1]',
>
> '/<(\/)?[ou]l>/Xis' => '[\\1list]',
> '/<(\/)?li>/Xise' => '( "\\1" == "" ? "[*]" : "" )',
> );
> $string = preg_replace(array_keys($arr_replace),
> array_values($arr_replace),
> $string);
> return $string;
> }
>
> As I mentiones before, keep in mind that reg-exp can be rather
cryptic
> sometimes. Also, this is the raw code, it should be optimized but
I'm
> feeling really lazy right now, so it should have to wait for a
better
> ocasion.
>
> It's up to you to decide wheter you'll use this function or
not, what I
> would recommend you is not to forget about regexp and give them a
try
> later (when you're more familiar with PHP), and I would also
recommend
> you to use PREG family rather than EGREP.
>
--- End Message ---