Re: [PHP] array_sum($result)=100

2006-09-24 Thread Penthexquadium
On Sun, 24 Sep 2006 19:06:11 +0300, "Ahmad Al-Twaijiry" <[EMAIL PROTECTED]> 
wrote:

> Hi everyone
> 
> I have array of numbers and I want to get out of it a list of numbers
> that if I sum them it will be 100, here is my list (for example ) :
> 
> $list = array(10,20,10,10,30,50,33,110,381,338,20,11,200,100);
> 
> 
> I want the result to be :
> 
> $result = array( 10,20,10,10,50);
> 
> as you can see in the array $result , if we array_sum($result) the
> result will be 100.
> 
> is they any algorithm to do this ?

I think you can try to sort the array in reverse order, and then
calculate the sum of numbers in loops (end loop when the sum is larger
than target sum).

It seems there is no algorithm can do this quickly.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP jump to other page

2006-10-04 Thread Penthexquadium
On Thu, 5 Oct 2006 01:17:41 +0700, Groundhog <[EMAIL PROTECTED]> wrote:

> how can I jump to another page after IF..ELSE statement, for example:
> 
> IF (statement == TRUE)
>{ stay on this page, index.php }
> ELSE { jump to index2.php}
> 
> -- 
> Come and Visit My Blog
> http://ubuntu-ku.blogspot.com
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

if (!statement) {
header('Location: index2.php');
exit;
}
// other codes...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] quick question about preg_replace

2006-10-04 Thread Penthexquadium
On Wed, 4 Oct 2006 23:19:58 +0200, "Martin Bach Nielsen" <[EMAIL PROTECTED]> 
wrote:

> Hi all.
> 
>  
> 
> I have written a guestbook (I know, there's a ton out there), which until
> recently did not get any spam, so now I'm trying to remove the spam-ad by
> using preg_replace:
> 
>  
> 
> $melding = preg_replace('/( temporarily cut-off due to spam-suspicion.", $melding);
> 
>  
> 
> However, this only makes the problem half-solved, since I also want any text
> before the link to be replaced with a message as stated above. The above
> line removes anything after ' 
> Is there any way to make the above line to include anything before the  href=// ?
> 
>  
> 
> I have tried different options, and yes, I have read the php manual on
> preg_replace, but I might not have properly identified how to get the text
> in front modified.
> 
>  
> 
> Thankful for any hints, tips, links, anything that helps :-)
> 
>  
> 
> Regards,
> 
> Martin Bach Nielsen 
> 

If you only want to replace the line including url(s) by a message, a
simple regular expression is enough.

http://www.example.com/\";>example line.\n"
 . "Another line.\n"
 . "http://www.e.com/ads/show?n=123\";>123 (456)\n"
 . "End Line.\n";

$melding = preg_replace("/.*?", $melding);

echo $melding;
?>

The script above will output:

This is a spam.

Another line.

End Line.

-- 
Sorry for my poor English.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Help on objects

2006-10-04 Thread Penthexquadium
On Thu, 05 Oct 2006 02:47:59 +0100, Deckard <[EMAIL PROTECTED]> wrote:

> Hi,
> 
> I'm trying to lay my hands on PHP OOP, but it's not easy :(
> I've read several examples in the web, but cannot transpose to may case.
> 
> I'm trying to set a class to make SQL inserts in mysql.
> 
> I have the class:
> -
>  
>   class dBInsert
>  {
>   // global variables
>   var $first;
>   
>  // constructor
>  function dBInsert($table, $sql)
>  {
>   $this->table = $table;
>   $this->sql   = $sql;
>   
>   return(TRUE);   
>  }
> 
> 
>   // function that constructs the sql and inserts it into the database
>   function InsertDB($sql)
>{
> 
> print($sql);
> // connect to MySQL
> $conn->debug=1;
> $conn = &ADONewConnection('mysql');
> $conn->PConnect('localhost', 'deckard', 'ble', 'wordlife');
>   
>   if ($conn->Execute($sql) === false)
>   print 'error inserting: '.$conn->ErrorMsg().'';
>   
>   return (TRUE);
>}
> }
> 
> 
> and the code that calls it:
> 
>  
>  include_once("classes/dBInsert.php");
>  $sql = "INSERT INTO wl_admins VALUES ('',2)";
>  $dBInsert = new dBInsert('wl_admins', '$sql');
>  $dBInsert->InsertDB('$sql');
> 
> ?>
> 
> 
> but it's not working ?
> 
> Can anyone give me a hand here ?
> 
> I've read the manuals, examples, etc.
> 
> Any help would be appreciated.
> 
> Best Regards,
> Deckard
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

You'd better learn the basic knowledge of PHP. There are several obvious
mistakes in your code.

> $dBInsert = new dBInsert('wl_admins', '$sql');
> $dBInsert->InsertDB('$sql');
Note that variables will *not* be expanded when they occur in single
quoted strings.

> $this->table = $table;
> $this->sql   = $sql;
The two variables seemed useless.

> $conn->debug=1;
> $conn = &ADONewConnection('mysql');
Called $conn before creating it.

And, I could not to know what is the purpose of this class.

PS, a description such as "it's not working" is useless for solving the
problem.

-- 
Sorry for my poor English.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unicode Problem

2006-10-05 Thread Penthexquadium
On Thu, 05 Oct 2006 18:14:59 -0400, [EMAIL PROTECTED] wrote:

> I have a webpage that allows users to post news stories for their department. 
>  The site uses AJAX to send the data to the webserver.  The problem I'm 
> having is when the user uses some unicode characters like bullets or MS Word 
> quotes, the page comes out weird.  
> 
> Here's the process.
> 1. The user enters the story and clicks save.
> 2. The javascript uses the escape function to turn the text into something 
> that can be posted to the server.  This function turns spaces into %20, but 
> it turns unicode characters into a longer string like %u.
> 3. The javascript then sends the data to the processing page.
> 4. The PHP processing page receives the data and saves it to the mySQL 
> database server.
> 
> The problem I see is that any unicode character is saved in it's escaped 
> unicode sequence.  For example a bullet is saved into the database as a 
> literal %u2022.  What I need to know is what function can I use so that it's 
> either saved as the unicode bullet character or displayed back on the page as 
> the bullet?  
> 
> Thank you
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

If you post that data via POST method, use encodeURIComponent() to
encode the string, and then the server-side script can accesses it
directly.

--
Sorry for my poor English.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] ECHO $variable

2006-10-08 Thread Penthexquadium
On Mon, 9 Oct 2006 00:23:00 -0700, "benifactor" <[EMAIL PROTECTED]> wrote:
> you should try this...
> 
> $saved_message_title = '1 Peter 5:7 "Cast all your cares on Him for He
> cares about you"';
> - Original Message - 
> From: "Ron Piggott (PHP)" <[EMAIL PROTECTED]>
> To: "PHP General" 
> Sent: Saturday, October 07, 2006 11:39 PM
> Subject: [PHP] ECHO $variable
> 
> 
> > In one of my scripts I have
> > 
> > 
> > 
> > where
> > 
> > $saved_message_title is 1 Peter 5:7 "Cast all your cares on Him for He
> > cares about you"
> > --- note the " 
> > 
> > When this is displayed on the screen $saved_message_title reads
> > 
> > 1 Peter 5:7 
> > 
> > I am assuming the " closes the value=
> > 
> > How may I echo this to the screen and have the full text be displayed,
> > not just 1 Peter 5:7 ?
> > 
> > Ron
> > 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

His problem is in HTML, not PHP.

Uses htmlspecialchars() or htmlentities() to convert special characters
to HTML entities. The double quote will becomes """ so that it can
be display correctly.

--
Sorry for my poor English.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] unexpected T_STRING parse error

2006-10-10 Thread Penthexquadium
On Tue, 10 Oct 2006 09:18:18 +0200, Ilaria De Marinis <[EMAIL PROTECTED]> wrote:
> Hi list,
> I got a php error in my apache log:
> 
> PHP Parse error:  parse error, unexpected T_STRING in 
> /var/www/html/dummy/typo3conf/ext/direct_mail/locallang_tca.xml on line 1
> 
> This is line 1 of locallang_tca.xml file
> 
> 
> I try to switch "short_open_tag" to off in php.ini, but I got a bad page 
> visualization.
> In fact it's visible also source code while displaying pages.
> 
> Any ideas?
> Thank in advance
> 
> Ilaria
> 
> -- 
> 
> De Marinis Ilaria
> Settore Automazione Biblioteche
> Phone: +3906-44486052
> CASPUR - Via dei Tizii ,6b - 00185 Roma
> e-mail: [EMAIL PROTECTED]
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

';
// ...
?>

--
Sorry for my poor English.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Passing JAVASCRIPT variable to PHP Script...

2006-10-10 Thread Penthexquadium
On Tue, 10 Oct 2006 03:09:42 -0700 (PDT), Captain <[EMAIL PROTECTED]> wrote:
> 
> Hi geeks,
>   i am uploading a file to server. Uploading part is working fine. i
> am struggle with minor part. actually before uploading file, i am checking
> for existance of a file. If it is not exists, directly i am uploading that
> file. If it exists, i sud ask user that "This file is exits. Do You really
> want to Upload it?"...If YES, i will overwrite it. otherwise, i won't do
> anything.
>  i am using javascript for popup windows. i used confirm()
> function(CANCEL / OK).
>  the problem is, i am not able to get the variable value for php
> script. Of course, php is server side programming language & javascript
> client side programming language.
> Plz see my code & give the solution.
> 
> See my progress:
> 
>  "upload.php"
> 
> # Checking for the File existance
> if (file_exists($fullPath)) {
>echo "if(confirm('This
> file is already Exists ! Do You Want to Duplicate ?')) { var s=1;} else {var
> s=0;} ";
> 
>$decide=" language='JavaScript'>document.write(s)";
>echo "$decide";
>if (!$decide) {
>   // Don't Upload
> exit;
>}
>else {
>// Upload the file
>}
> 
> In this code, echo "$decide"; is printing whether 1 or 0. But by using that
> variable, i cudn't proceed further. Bcoz it is not useful for manipulating.
> 
> * Is anyway to store that variable value in a static file, so that, i can
> proceed easily.
> * Is it possible to execute shell commands by javascript, so that i can
> create file & store this variable.
> 
> If it is not possible, plz give any other solution.
> Expecting ur reply.
> 
> Thanks in advance
> Prabhakaran.
> -- 
> View this message in context: 
> http://www.nabble.com/Passing-JAVASCRIPT-variable-to-PHP-Script...-tf2415628.html#a6733549
> Sent from the PHP - General mailing list archive at Nabble.com.
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

This is my ideas:

If the file has already existed, the server-side script could save it in
a place temporarily, and marks the file by an unique identification
(such as md5 checksum). And then the the server-side tells the
client-side file exists and gives it the id. If the user choose
overwrite, the client-side only need to post the received id, do not
need to upload the file again.

--
Sorry for my poor English.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regular expressions

2006-10-14 Thread Penthexquadium
On Sat, 14 Oct 2006 23:19:13 +0200, "Morten Twellmann" <[EMAIL PROTECTED]> 
wrote:
> I'm trying to understand these regular expressions, but I can't make them
> work...
> 
> All I want to do, is to find the first occurrence of some text inside the
> HTML tags  and .
> 
> Example string: "October 14, 2006Welcome to my
> homepageWe're happy to announce..."
> 
> must return:
> 
> "Welcome to my homepage"
> 
> 
> I tried with:
> 
> preg_match(']*>(.*?)', "Welcome to my homepage",
> $matches, PREG_OFFSET_CAPTURE);
> print_r($matches);
> 
> but got nothing...
> 
> Can anyone tell me how to do this?
> 
> (I tried the above expression in EditPad Pro 6 and it worked...!)
> 
> Sincerely,
> 
> Morten Twellmann

The regex you wrote lacks separator. That PHP statement will occur an
error:

> Warning: preg_match() [function.preg-match]: Unknown modifier ']' in
> /path/file.php on line X

The statement should be:

preg_match("/]*>(.*?)<\/h1>/i", "Welcome to my homepage",
$matches, PREG_OFFSET_CAPTURE);
print_r($matches);

--
Sorry for my poor English.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php