Re: [PHP] Unsetting a header

2007-10-21 Thread Rafael
Let me reiterate, I want this page to get cached, but not based on an 
Expires: header. Rather a Last-Modified header.


	Have you tried setting the value to FALSE, NULL, or something else? I 
recall having read something along those lines. I'll see if I can find 
it again, meanwhile you could experiment a little.


Regards

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



Re: [PHP] window.open() and search engines

2007-10-23 Thread Rafael

It depends on the way you do it, for instance, something like
  ...
will, but if you use something like
  ...
chances are it won't.

Edward Kay wrote:

Can anyone say for sure whether window.open() links get spidered by
search engines?


From my experience they don't, but I use a custom Javascript function to
open pop-ups.


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



php-general@lists.php.net

2007-12-01 Thread Rafael

Jim Lucas wrote:

Dan wrote:
Unfortunatly javascript can't access the filesystem so it can't get 
filenames.  The closest way you could do something like this would be 
to use Java (not javascript, totally different).  It's a permissions 
thing, just the way JS and everything else is designed.


- Dan


[···]


Library should be compatible with Firefox (Lin, Win, Mac), IE and 
Safary.



Thanks in advance for any suggestion(s).

Andrei 




In fact you can access the filesystem with "signed" javascript scripts. 
 Which by "signing" you Javascript, you will be allowed to access the 
local file system.


But, again, it is all about the permissions.

Jim
	Actually no. Javascript doesn't allow for client's FS access for 
security reasons, as noted before.


	What you're probably talking about is IE's proprietary implementation 
and the use of COM objects (and there goes the security), but Andrei 
says the solution should be cross-browser, so this doesn't look like an 
option.


Rafael.

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



[PHP] Re: string problem

2006-07-10 Thread Rafael
	Well, if that's the pattern, you can search for >'%< and return 
anything between this and >%'<; if you can use PCRE try something like

  if ( preg_match('/'%(.+?)%'/X', $str, $matches) ) {
  echo  $matches[1];
  }
Now, if the expression can only have: upper-case letters, numbers & "-", 
then use  "/'%([-A-Z0-9]+)%'/X"  instead of  "/'%(.+?)%'/X"


weetat wrote:

Hi all ,

 I am using PHP 4.3.2 , MYSQL database and Red Hat Entreprise OS.

 I have the SQL statement which store in $str variable  as shown below :
 How to get the '%WS-X5225R%' from $str variable ?



$str = " SELECT DISTINCT(tbl_chassis.serial_no),tbl_card.card_model, ";
"tbl_chassis.host_name,tbl_chassis.chasis_model,tbl_chassis.country,";
"tbl_chassis.city,tbl_chassis.building, 
"tbl_chassis.other,tbl_chassis.status,tbl_chassis.chasis_eos,tbl_chassis.chasis_eol,tbl_chassis.chasis_user_field_1,tbl_chassis.chasis_user_field_2,tbl_chassis.chasis_user_field_3" 
"from tbl_chassis tbl_chassis,tbl_card tbl_card "
"WHERE tbl_chassis.serial_no = tbl_card.serial_no AND 
tbl_card.card_model LIKE'%WS-X5225R%'";



thanks

--
Atentamente / Sincerely,
J. Rafael Salazar Magaña

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



[PHP] Re: Formating a Double

2006-09-06 Thread Rafael

number_format()

Now, why do you say it's not working properly?

Note: number_format() takes a float as an argument, not a string, and 
even if it were, the double would be casted to string.


Phillip Baker wrote:

Greetings All,

I am trying to format a double to use thousands seperators and such.
number_format does not appear to be working properly for this.
My guess is cause I am trying to format a double rather than a string.
Is there anything out there that will allow me to format a double to 
include

a comma as a thousands seperator.
Thanks.



--
Atentamente / Sincerely,
J. Rafael Salazar Magaña

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



[PHP] Re: Check HTML style sheet?

2006-10-21 Thread Rafael
	For PHP, the HTML is pretty much a bunch of chars (a string) and 
nothing more, which that lets with one (initial) option: search the HTML 
for a given string.


Marc Roberts wrote:
Is it possible to use php to check that the .css file in the html of a 
web page is the correct one e.g. check if the file included in the html 
is new.css.


I think I will have to write a regex but if anyone has any ideas (or 
already has a regex to do this), it would be much appreciated.


Thanks,
Marc


--
Atentamente / Sincerely,
J. Rafael Salazar Magaña

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



[PHP] Re: URL output query

2006-02-27 Thread Rafael

Hi Chris,
	if the only thing you want is to get the domain (having the whole URL) 
you have more than one way to solve it.  Chris -it's a little akward 
that Chris answered to Chris- already told you about parse_url(), and 
since we're talking about strings, I would suggest something like

  $domain = preg_replace('{^([a-z]+://[^/]+).*$}X', '%1', $uri);

Chris wrote:

Greetings PHP folks,

Which PHP function do I use if I want to achieve the following :

http://www.somesite.com/gallery/pics.php is the url...how do I get it to
read only http://www.somesite.com in the browser address bar without the
rest of the directory and filename appearing ?

--
Atentamente,
J. Rafael Salazar Magaña
Innox - Innovación Inteligente
Tel: +52 (33) 3615 5348 ext. 205 / 01 800 2-SOFTWARE
[EMAIL PROTECTED]
http://www.innox.com.mx

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



[PHP] Re: Optional pass-by-reference parameters?

2006-02-27 Thread Rafael
	If "some_func( &$var = NULL )" didn't work, then you're most likely 
using PHP 4.  If that's the case then you could try passing an argument 
by reference in call(real/execution)-time, e.g:


  function some_func( $optional = NULL ) {
···
  }

  some_func();
  some_func(&$my_var);

Note: beware that the directive "allow_call_time_pass_reference"
  _must_ be On in your php.ini
  This functionality is deprecated, since PHP 5 does allow
  optional arguments-by-reference.

TomS wrote:

I would like to have an optional pass-by-reference. i.e. you can call the
function w/o the variable. Basically, like how you don't need to pass
$matches to the preg_match function. I've tried, function some_func(&$var =
null) and this doesn't work. func_get_args only gets copies, does anyone
have any other solutions?

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

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



Re: [PHP] Re: URL output query

2006-02-28 Thread Rafael

Chris wrote:

Rafael wrote:


Hi Chris,
if the only thing you want is to get the domain (having the whole 
URL) you have more than one way to solve it.  Chris -it's a little 
akward that Chris answered to Chris- already told you about 
parse_url(), and since we're talking about strings, I would suggest 
something like

  $domain = preg_replace('{^([a-z]+://[^/]+).*$}X', '%1', $uri);


We are two different people !? Not sure how that's difficult.


	Did I say difficult?  What I meant is that seing a question from Chris, 
immediately followed by a message from Chris leds to think it's an 
"extension" of the question (maybe something he forgot, or something 
new), but it wasn't, it was an answer from (a different) Chris, hence a 
little akward.

--I hope this makes things clear for you.

I don't know why you'd use a regular expression when you can use a 
function instead (easier to maintain, it'll be faster, you won't make a 
mistake)...


	What I sent was a way to get what he wants in 1 function call.  You 
should understand that preg_* family functions are just like str_* 
family functions, they work with strings, it's as simple as that -and 
yes, they're functions too.


	Now, probably parse_url() relies in preg_* or ereg_* functions -that 
wouldn't be rare-, so I don't think parse_url() would be faster than 
preg_replace(), and even if it is the difference would be meaningless; 
and neither I see how writing more lines would be faster.  I also would 
like to know how the use of parse_url() would guarantee that he won't 
make a mistake.


	Man, I can only conclude you've satanized preg_* functions because of a 
lack of knowledge, and I suggest you to investigate more about them, 
they're quite useful the same for easy and complex tasks.  Someone said 
once that you don't know the power of regexp until you know them, and 
that's definetely true.



But of course there is always more than one way to solve a problem.


	Agreed, so Chris may consider whatever he likes the most.  If he, like 
you, thinks that regular expressions are too complex and don't like the 
idea of knowing them, then he will most likely choose parse_url() -which 
is just fine.

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

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



[PHP] Re: preg_replace problem

2006-03-01 Thread Rafael
	Is there any special reason why you want to solve this with regular 
expressions?  As far as I see, there's a couple of problems with your code,

a) $file = dog.txt  should be  $file = 'dog.txt',
b) $getOldValue has the _array_ resulting of parsing the INI file,
   hence you should write $getOldValue, since it's the complete file
   (I won't say anything about performance),
c) you're using a regular expresion to increment the value in a
   specific key/index, and you don't need regexp for that, and
d) you're not saving the whole file, only the "setting" (entry) for
   "today", hence you overwrite the file and leave only "today = n"

What do you think of something like this (a bit changed):
$file= 'dog.txt';
$today   = date("Ymd");
// we read the file,
$getOldValue = parse_ini_file($file);
// set or increment the value in "$today" key,
   @$getOldValue[$today] ++;
// and write back the whole INI file
// note: what we have is an array, not a string
$str_ini = '';
foreach ( $getOldValue as $date => $value ) {
$str_ini .= "$date = $value\n";
}
file_put_contents($file, $str_ini);

Benjamin Adams wrote:

$file = dog.txt;
$today = date("Ymd");

function incDate($new, $date){
//$date = settype('int');
return $new.($date++);
}

$getOldValue = parse_ini_file($file, 1);
$newValue = $getOldValue[$today] + 1;
$oldDate = $today . " = ". $newValue;
$newDate = preg_replace('/(\d+\s\=\s)(\d+)/ie', 'incDate("$1","$2")',  
$oldDate);

file_put_contents($file, $newDate . "\n");

This works with one file but with multi lines I'm having trouble:
if the file has:
20060301 = 34
20060302 = 3
the file after script will be:
20060302 = 4

I want it to preserve the previous lines
so output should be:
20060301 = 34
20060302 = 4

Help would be great, thanks
Ben

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

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



Re: [PHP] Coding Practice: Use global $var or pass in by refernce

2006-03-03 Thread Rafael

Andreas Korthaus wrote:

Hi Gustav!

Gustav Wiberg wrote:

My oponion is that is insane to use global variables. The main 
drawback with global variables is that is very easy to mix up 
variables, and keep track of what variable belongs to what. So an 
advice: Don't use it!



Ok, so what's your recommendation to solve the problem with using a DB 
class in many other objects/methodes? Think of a DB class:


class DB {...}

And a lot of classes which want to use the DB class:

class Foo {
  function saveChangesInDb() {...}
}

class Bar {
  function saveChangesInDb() {...}
}

- You can use a global "$db = new DB..." and pass it to every 
class/methode,


- you can make $db "global" in each methode,

- you can create a new instance ("new DB") in every methode (but you 
usually only want a single DB-connection per script, and where do you 
pass config-data to access the DB?) or


- use a factory/singleton, which is not so much better than a global 
variable (and again, what about config-data?).



So what's the way you'd recommend and why?


	IMHO, the only way a global variable would have sense is in an 
environment where you can be assured there's a "DBClass" $db instance, 
and that it would never ever be a $db var that's not a DBClass instance 
nor will $db ever be missing.  So, can you guarantee this at the present 
and to the end of times? :)


	I think it would be better to create an instance of $db whatever the 
script you need it, and pass it to every class-constructor as a 
byref-parameter; i.e.


  $db =& new DBClass();
  ···
  $class1 =& new Class1($db);
  ···
  $class2 =& new Class2($db);

	Now, if you insist on using global vars, then maybe, just maybe, it 
would be better to let that byref-param be optional, and check in the 
constructor for a global DBClass instance $db if no DBClass instance was 
given, but then again the problem would be pretty much the same.  Try 
not to rely on global vars, bear in mind that global vars almost always 
give too little info and do not reflect themselves on the function 
prototype --well, if you have a smart IDE/editor that understand PHPDoc 
comments (or something like that) and you do document their existance, 
it might not be that bad, but still try to avoid them.

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

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



[PHP] Re: Converting HTML to BBCode [medium]

2006-03-06 Thread Rafael
	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
   * @returnstring
   * @since Mon Mar 06 23:44:40 CST 2006
   * @authorrsalazar
   */
  function to_bbcode( $string ) {
static  $str_http_valid = '-:\/a-z.0-9_%+';
$arr_replace= array(

"/(.+?)<\/a>/Xis"
 => '[link=\\2\\3]\\4[/link]',

"//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---


Convert from HTML to BBCode



Body:  


';

// Declare HTML tags to find, and BBCode tags to replace them with

$linkStartFind = '' . "$text" . '';

?>


---/CODE---

Now, most of this doesn't work. Here is the test code I put into the 
first textarea:


---TESTCODE---
Testing bold code

Testing italics

http://link.com";>Testing link

http://image.com/img.jpg"; border="0" />

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]

http://link.com\";>Testing link[/url]

http://image.com/img.jpg\"; border=\"0\" />

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

Re: [PHP] Re: Converting HTML to BBCode [SOLVED]

2006-03-07 Thread Rafael

Hi,
	I'm glad it worked (so far, hehe)  Also, there's something I forgot to 
tell you (though I think you may as well be already doing this): there 
will be some unknown tags for the to_bbcode() function (even maybe some 
variations of those that it should recognize but it won't), so you 
should take care of those tags too, with something similar to this:


  $text = to_bbcode($text);// try to convert to BBCode
  $text = strip_tags($text);   // get rid of remaining tags
  $text = htmlspecialchars($text); // replace basic HTML-entities

J_K9 wrote:

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:


[···]


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


	Good luck on that. Oh, a little correction: it should be PCRE not PREG, 
"preg_" is the functions prefix (my mistake, sorry)

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

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



[PHP] Re: preg_replace problem (or possibly bug)

2006-03-08 Thread Rafael
	What I see in the page you sent is a [url] "bbcode-tag" that is not 
closed (i.e. it has no [/url] or it's not displayed)


	If that's not the problem, could you send some example that isn't 
working (and some others that are working)


Michael wrote:

I am currently writing a forum system, but at the moment I have a bug
that no one can seem to get to the root cause of. Basically I am using
preg_replace with the pattern as "'\[url=(.*?)\](.*?)\[/url\]'is".
However for most links it works fine but for others it just doesn't
render the bbcode to a link, we were trying to get to the root cause
of it here 
http://michael-m.co.uk/forums/index.php?action=view_topic&id=31&page=1
but we failed. I'm not really that good with regular expresions so
that might explain why. Also we had never noticed these problems until
about 3 days ago, but I see no reason why it could have started. All
help will be greatly appreciated, you may use the username php and the
password php to log on to do your own tests but please keep the
testing to the topic (and the spam forum if necessary).

Many Thanks,
Michael Mulqueen


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

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



Re: [PHP] Calling Curt Z, Curt Z to the white courtesy phone please

2006-03-08 Thread Rafael

Also (not sure if all are missing or not):
a) when looking for a specific function in PHP.net you can also use
   other word-separators and not only "_", such as: -, + and space
   (or %20), haven't heavy-tested this, so may as well be others
b) if possible, look for a mirror prepending you country TLD as a
   subdomain, such as http://mx.php.net (it can also be more than
   one for the same country, e.g. http://mx2.php.net, and so on)
c) when reading some parameters use  "print_r()", such as
 print_r($_GET);
d) add a little text about some (repeatedly discussed) basic PHP
   directives such as register_globals and magic_quotes_gpc (and
   try not to rely on the first one and check for the later)
e) when getting a (notice, warning or error) message send it along
   with you posting, as well as the the line that trigger that
   message (and about two lines before and after that line)
f)

Curt Zirzow wrote:
[···]

You mean this? :)
  http://zirzow.dyndns.org/php-general/NEWBIE

It might need some rewording and a few tweeks here and there. It is
almost turning more into a php-general charter.

For those wanting to know the original:
  http://zirzow.dyndns.org/php-general/NEWBIE.orig

Curt.

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

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



[PHP] Re: Make all emails links

2006-03-08 Thread Rafael
	I agree, your regexp are bad (jk)  What you need is a regexp that 
matches an email address.  Look for something like "regexp email" on 
Google (without the quotes) or something similar and you should find 
some regexp to validate an email address; once you have it use it with 
preg_replace() like Bekko did -or its EGREP equivalent.


Example (using the first one I found, a bit modified):
  $regexp = 
'/[EMAIL PROTECTED]/Xi';

  $string = preg_replace($regexp, 'mailto:$1";>$1', $string);

El Bekko wrote:

Benjamin Adams wrote:


I'm pulling data from a database;
When the data is pulled emails look like
[EMAIL PROTECTED]

Is there a way to just make all email address in the text that it 
pulls so,

"bla bla bla okjsokdf [EMAIL PROTECTED] ksnow noduowe..."

Make the email in the text be a mailto link automatically?

Thanks
-Ben



With a RegExp ;)

Something like this (yes my RegExp is bad):

$message = preg_replace("[EMAIL PROTECTED]","href=\"mailto:$1\";>$1",$message);


?>

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

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



Re: [PHP] Is this password protection script secure?

2006-03-15 Thread Rafael

Oscar Gosdinski wrote:

Instead of using a hash if the password string, i prefer to save the
following in the password field of my user's table:

md5($user . $password)


This is a good idea, IMHO of course.


There are some md5 databases around that can be used to get the
cleartext password from the hash if your database is compromised, if
you use this method it's difficult to get the cleartext password
because it depends on the user and you are also validating if the user
exists.


	Well, it's a little hard to obtain the "cleartext" from something in 
MD5-hash, though it's possible via brute-force.  You might as well try 
to use some other method, such as SHA1, combine them or do whatever you 
want to alter the initial clear-text version to obfuscate it (like you 
did above)



However, i have a question. Which is better?, the md5 function
provided by PHP or MySQL? i used the MySQL function because i didn't
compile PHP with support for hash.


	The one in JavaScript :)  AFAIK, every MD5 function is based on the MD5 
algorithm, so the implementation is rather similar (if not the same)  Of 
course, the result is always the same.

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

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



[PHP] Re: setcookie security concerns

2006-03-15 Thread Rafael
	As far as I see... I can't see any risk.  Cookies are saved in the 
client machine (i.e. the one visiting your site), so any code he might 
send will be used with him only, and it will not affect other users nor 
the scripts in the (remote) server.


	Now, you're not using the input value in anything similar to an eval() 
expression, hence should some PHP code be sent and it would only be 
printed, no harm in that either.


	Inspite of all this, I would really recomend you not to rely on 
register_globals=On, since: it's not a good idea, it's actually 
deprecated (someday it will be removed) and makes your code a little bit 
more confused, since it's not clear where do that variables come from.


> 1. Is he right?
	Yes, and no.  In your specific case someone _could_ send you code 
instead of whatever you're expecting (and you don't validate the input), 
but it would be harmless for anyone other that himslef.


	Beware that the risk of code inserted in cookies, form-input elements, 
the Query string, etc., is real and it depends on the way you use the 
data received, and if you check it and how do you do it.


> 2. How does that work?
	Well, cookies are stored in your (client) machine, so you're able to 
modify whatever content they have.  One way to test this is using 
Firefox and an extension that allows you to edit cookies such as "Add N 
Edit Cookies" (play with the cookie of your own site)


> 3. If so, what do I do to correct this?
	Do not rely on register_globals, and don't ever trust on any input 
given by the user, treat all of them as enemies and check everything 
that comes to your mind --and more ;)


Note: this is how _I_ see it, so I could be ignoring something that 
other people did see.


tedd wrote:

Hi:

I've been using a php style switcher allowing users to change css. The 
code follows:


Within the head tags.




Within the body tags, allowing the user to select which style they want:

Green or href="switch.php?set=style1">Red


And, the corresponding (switch.php) php code is:



It's pretty simple. But recently, I had one person hammer me stating it 
was a security problem because I didn't validate the user input. As 
such, he says that someone could inject an arbitrary code and cause 
problems.


1. Is he right?

2. How does that work?

3. If so, what do I do to correct this?

Many thanks for any replies.

tedd

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

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



[PHP] Re: REG-EXPR: Allowing limited number of special chars in usernames

2006-03-15 Thread Rafael

Holger Sunke wrote:

I dont know that much aboput regular expressions and just want to
know how to find out the number of special (non alphanumeric)
characters in a string or how to match a string that contains less
than 3 special chars.


I don't really understand what you need, but...
- how to find out the number of special (non alphanumeric) characters
  $alpha = '[a-z0-9]';
  $special_chars = preg_replace("/$alpha+/Xi", '', $string);
  * this would replace any alpha-numeric char by... nothing, leaving
the "special chars" only, and strlen() will give you how many are
  * beware that you're saying *anything* other than alpha-numeric chars

- how to match a string that contains less than 3 special chars
  * as I said above, strlen() will give you the number of these chars:
  $num_special_chars = strlen($special_chars);


preg_match('/^[ -~äöüßÄÖÜ]+$/',$string)


will return TRUE if $string consists enterily of the chars between the 
square-brackets.


I hope this helped a little.


urrently im using a function

function valid_username($string) {
   if(strlen($string)<=16&&strlen($string)>5) {
  return(preg_match('/^[ -~äöüßÄÖÜ]+$/',$string));
   } else {
  return FALSE;
   }
}

This allows usernames of 6 to 16 length containing many special chars
and German "Umlaute". But this also allows usernames like "=)/(&%$"
what should not be.

So how to limit the number of special chars? This function should
just return fals if number of special chars > X

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

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



[PHP] Re: regular expressions and Phone validation

2006-03-15 Thread Rafael

Paul Goepfert wrote:

I have one small problem I don't understand the preg_replace() method.
 I understand the gist of what it does but I still don't fully know
what it does.  I have read the entry in the php manual about this and
I am still confused about it. I've never been any good with regular
expressions.


	Well, I'm not sure about what you don't understand.  Anyway, 
preg_replace() does "the same" as str_replace(), but using 
regular-expressions instead of just strings.  If you understand how do 
reg-exp work, then it should have no real problem, if the reg-exp are 
the problem then you better read a little more about them (the PCRE 
tutorial at php.net is really good, IMHO)



Here is the function in use:

function checkPhone ($Phone)

[···]

  $Phone = ereg_replace("[^0-9]", '', $Phone);
  if ((strlen($Phone)) <= 14)
return 
preg_replace("/[^0-9]*([0-9]{3})[^0-9]*([0-9]{3})[^0-9]*([0-9]{4}).*/",
 "(\\1) \\2-\\3", $Phone);

[···]


I think my problem is mostly what is returned when preg_replace executes?


	Well, what's inside parenthesis is "remembered" by preg_replace(), and 
you make reference to them using "\\n" or "$n" (where "n" is a number) 
in the "replace-string" (there are some exceptions, but that should do 
for now)  If you look carefuly, there are three expressions between 
parenthesis, and these are what you're referencing via "(\\1) \\2-\\3"


	Though, there's something I don't get it: in your reg-exp your ignoring 
any non-numeric character, but you already got rid of them with 
ereg_replace()... (??)

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

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



Re: [PHP] Re: setcookie security concerns [medium]

2006-03-16 Thread Rafael

(Comments inline)

tedd wrote:
[···]
One last question, considering the above code, would the following code 
be a suitable replacement?





	Actually, you receive $set via GET, so you should use $_GET instead of 
$_POST.  A lot of people use $_REQUEST (wich is a combination of $_POST, 
$_GET and $_COOKIE —check the manual), but I read somewhere that this 
isn't a good practice, though I don't recall why :p


  $set = $_GET['set'];
or even better would be something like
  $set = ( isset($_GET['set']) ? $_GET['set'] : $default_value );

I've used htmlentities() before to filter out user's input, but I don't 
know if that's sufficient to protect from all types of injections -- is it?


	No, it doesn't suffice this way --it does for the script we're talking 
about, but that's because you only use the data as part of the HTML 
code, so no more harm can be done with it.


	A tipical example would be a login script that uses the data as it 
arrives, for example:

  $login = $_POST['login'];
  $passw = $_POST['passw'];
  $sql   = "SELECT * FROM user\n"
  ."WHERE( login = '$login' AND passw = '$passw' )";

In this case, what happens if I send something like
  login: ' OR '1'='1' OR '0
  passw: doesnt care
? (I avoided the ' in the passw, just in case)
Well, we'll end up with an SQL similar to this
  SELECT * FROM user
  WHERE( login = '' OR '1'='1' OR '0' AND passw = 'doesnt care' )
and because of the priority of the AND / OR, we would have 3 separated 
conditions each enough to validate the user, as '1'='1' is true, then we 
have a validated user.


Now, if I can do this, I could change the logic a little...
  login: admin' AND '1'='1' OR '0
  WHERE( login = 'admin' AND '1'='1' OR '0' AND passw = 'doesnt care' )
In this case you should care about ' and " (depending on which one are 
you using)  Again, I read somewhere that the safest way is to use 
(emulated?) "prepared SQL statements", such the "?" SQL-parameters in 
ADODB, PEAR-DB and others.


	By the way, even causing an SQL error that is displayed to the user 
(the whole message or just a part of it) can reveal info that could be 
used to bypass your protection.

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

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



Re: [PHP] Re: setcookie security concerns [medium]

2006-03-17 Thread Rafael

(Comments inline)

tedd wrote:
[···]
 From what I've read (PHP Cookbook by Sklar and other sources) the 
reason why you don't want to use $_REQUEST is because it holds all the 
variables from six global arrays, namely $_GET, $_POST, $_FILES, 
$_COOKIE, $_SERVER, and $_ENV.


	Actually, the super-global variables used in $_REQUEST are $_GET, 
$_POST and $_COOKIE¹, and though there is a "gpc" directive I'm not sure 
if you can control the order they are read (but my guess would be that 
you do)

¹http://php.net/manual/en/reserved.variables.php#reserved.variables.request

When PHP creates $_REQUEST, it does so by adding the global arrays 
together in a certain order, namely EGPCS.  Normally, this would be OK, 
but if two (or more) of those arrays have a key with the same name, then 
that key value will be replaced with the last value read. For example, 
the value provided by $_GET('mykey') will be replaced by the value found 
in $_COOKIE ('mykey') in generating the value for $_REQUEST('mykey').


So, if you use $_REQUEST, then you can't reply upon where its values are 
derived.


	Well, I still don't remember the reason, but this could be a valid one 
:)  By the way, these are variables (arrays), so you should use 
square-brackets instead of parenthesis to specify an index (e.g. 
$_SERVER['SCRIPT_NAME'])

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

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



Re: [PHP] Converting a string

2006-03-17 Thread Rafael

Jay Blanchard wrote:

[snip]
If you have similar element names in $_POST, comething like:

$human_friendly = array("psFirstName" => "First Name");
foreach ($_POST as $ key => value) {
echo "Cannot leave {$human_friendly[$key]} blank"; 
}
[/snip] 


But I don't want to create another array, and should'nt have to


	Then you should change the name of the field.  Seriously, what do you 
expect the script to do, exactly? and once you know the answer, what 
would you do to achieve that?  Put that (emphasis to the second 
question) in words and someone might be able to help you.

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

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



Re: [PHP] Converting a string

2006-03-17 Thread Rafael
	Well, you didn't answer the second question, how would you do it?  So 
far I see a pattern: "ignore the lowercase letters at the beginnig and 
add a space before an uppercase" (this won't apply to all field names, 
and I hope you're aware of that), so try something like

  $text = preg_replace('/^[a-z]+\s*/X', '',
   preg_replace('/(?=[A-Z])/X', ' ', $name) );

	Now, a better way, IMHO, would be to use "_" as spaces and write the 
name of the field as you want it to appear (e.g. "First_Name"), so you 
just need to

  $text = str_replace('_', ' ', $name);
--pretty much simplier, isn't?
And... if you want to add a prefix (such as "ps") then make it 
configurable, so it can be changed anytime without effort.


Last comment: you should think about the question you didn't answer, and 
that might give you the solution to your problem.


Jay Blanchard wrote:

[snip]
Then you should change the name of the field.  Seriously, what
do you 
expect the script to do, exactly? and once you know the answer, what 
would you do to achieve that?  Put that (emphasis to the second 
question) in words and someone might be able to help you.

[/snip]

I expect that I can take a string, like 'psFirstName' and change it to
'First Name'. that way I don't have to worry about what some web
designer named his fields, I can turn them into human readable strings
without having to manually create a new array.

So far I have this

$newKey = preg_split("/([A-Z])/", substr($key, 2), -1,
PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);

Which returns;

Array
(
[0] => F
[1] => irst
[2] => N
[3] => ame
)

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

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



Re: [PHP] Get class name in static method

2006-03-21 Thread Rafael
	Yeap, that's the method we're using in PHP4, but when we tried to 
change to PHP5 we found out that the behaviour of debug_backtrace() had 
changed, and it's (was?) not even documented (well done, don't you 
think)  And we haven't found any issue with this solution (...in PHP4)


http://bugs.php.net/bug.php?id=34421
	There's also a bug report, and even a patch submited, but the 
devolopers haven't said anything else about this bug/feature in the bug 
thread, it seems it isn't a priority for them, and this was something 
that it really made angry at the time (and I'm still not too happy with 
this problem and they're position of passive-won't-fix)  I guess to vote 
is the only thing we can do, but don't expect it to have an impact though.


Grant Young wrote:

Not sure about PHP5, but for PHP4 I found this hack solution at:
http://passivedigressive.com/archives/2005-02/php-static-class-name-solution/ 

There are probably all sorts of issues with this approach, but it solved 
the problem at the time...

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

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



[PHP] Re: Word to txt

2006-03-29 Thread Rafael

Pray to St. Google with something like "doc2txt"

Ministério Público wrote:

I'd like to know if any of you know if I can and if I can how do I do to
transform a Word documento to txt with php.

What I'd like to do is offer the user in my site to upload a word file and
the script transforms the word to txt and saves to server, my site already
can receive txt.
Thanx to you all.

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

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



[PHP] Re: stripping enclosed text from PHP code

2006-04-09 Thread Rafael

Winfried Meining wrote:
I am writing on a script that parses a PHP script and finds all function calls 
to check, if these functions exist. To do this, I needed a function that would 
strip out all text, which is enclosed in apostrophes or quotation marks. This 
is somewhat tricky, as the script needs to be aware of what really is an 
enclosed text and what is PHP code. Apostrophes in quotation mark enclosed text 
should be ignored and quotation marks in apostrophe enclosed text should be 
ignored, as well. Similarly, escaped apostrophes in apostrophe enclosed text 
and escaped quotation marks in quotation mark enclosed text should be ignored. 

The following function uses preg_match to do this job. 

[···]
I noticed that this function is very slow, in particular because 


preg_match("/^(.*)some_string(.*)$/", $text, $matches);

always seems to find the *last* occurrence of some_string and not the *first* 
(I would need the first). There is certainly a way to write another version 
where one looks at every single character when going through $text, but this 
would make the code much more complex.


	IIRC regexp search from left to right but match from right to left, 
hence going trough the string while the first part matches and going 
backwards every time the next part fails to match, and so on for the 
whole expression, that's why "(?>...)", "once-only subpatterns", exists for.


	Now, you're telling (from left to right) to look for "any sequence of 
any characters followed by 'some_string' and, once again, followed by 
any sequence of any characters".  As long as "(.*)" matches it will loop 
the whole string till it fails, once it does it will try to match 
"some_text", if it doesn't it will try to match "some_string" once again 
from the current position minus one and so on, until it matches (or 
"(.*)" fails --at the beginning of the string), after "some_string" 
matches it will repeat the first step for the second "(.*)" on the 
pattern, so the process will be quite slow.

--I hope this has had some sense for you (somehow it lost it for me)

	Also, by default regexp are "greedy", which means "+" and "*" 
meta-characters will go on and on.  In your case, you most likely will 
need to "limit" this behaviour by specifying them as "ungreedy" (that 
is, it will try to match the next part after each "+"/"*" matches), you 
can do this adding a "?" after these meta-characters (e.g. ".+?-")


I wonder, if there is a faster *and* simple way to do the same thing. 


Mhh...  what about something like
  preg_replace('/(["\']).*?(?? it's not 100% accurate, though, if you find something like '\\' it 
will fail --I guess you should replace these before running the regexp


	After trying a little, I found that this code below seems to be quite 
acceptable, you may want to try it:

  /**
   * Returns an array with the identified function-calls found
   * (including "function declarations", e.g. "function my_func")
   *
   * @param string  $code
   * @returnstring
   * @since Mon Apr 10 01:13:28 CDT 2006
   * @authorrsalazar
   */
  function getFunctionCalls( $code ) {
  $result = FALSE;
  // try to strip away literal strings
  $code   = preg_replace('/(["\']).*?(?((?:(?<=\b)function\s+)?\w+)\s*)\(/Xi',
  $code, $arr_matches) ) {
  $result = $arr_matches[1];
  }
  return  $result;
  } // getFunctionCalls()

I recommend you:
-> http://php.net/pcre
 > http://php.net/manual/en/reference.pcre.pattern.syntax.php
 > http://php.net/manual/en/reference.pcre.pattern.modifiers.php
--
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

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



[PHP] Re: 2 questions: Search in array and detect JS

2006-04-15 Thread Rafael

Ryan A wrote:

Hi,
Like the subject says; I have two questions:

1) Is it possible to detect JavaScript via php... and yes I do know that JS
is client side while PHP is server...but how else to do it?
The reason I ask is before serving an AJAX page I would like to make sure JS
is enabled, if not, serve the other "normal page"... I am sure I am not the
first person to come accross this little problem, how did you solve it?

I have seen some suggestions on google like having a hidden form field  and
using  js to put a value in it, if it exists when the form is sent then JS
is on..if not, its not... but that method is not the best in an AJAX
situation...right?


	You don't specifically what would change in the "AJAX page" (other than 
make use of AJAX)  If it's possible, I would recommend you to serve the 
normal page and include a snippet to modify its behaviour, so you can 
"save the page reloads" (tipical use for AJAX), e.g.

  window.onload = function( ) {
if ( document.frmTest ) {
  document.frmTest.onSubmit = function( ) {
// verify values with ajax before submiting
  }
}
  }
  // "normal version" of the page
This way you only change the behaviour when its supported (of course, 
you would also need a verification for Remote Scripting/AJAX support)


	And I agree with the others about serving the "normal version" first, 
and redirecting via JS (when the behaviour is too different)



2) How can I search in an array for a particular word?

eg: in an array "movie" I have this kind of data:
movie_name=> some movie
cast=> Jim Carrey, Richard Pryor, Eddie Murphy

I want to search on either "Richard" or "Richard Pryor" (must be case
insensitive too)
something like a SELECT with a LIKE %% statement

I have been fooling around with in_array() but not getting anywhere
fast. am I on the right track?
Links, code examples or advise would be as alwaysappreciated.


	First, I would suggest you to re-analize why are you searching in an 
array (of course, you're the only here who knows the reason)


	Second, you may encounter array_filter() useful, this function uses a 
callback user-defined function to "filter" the elements in a given array 
and build a second (which is the value it returns), so you may use this 
function along with strpos() (or some other)

  http://php.net/manual/en/function.array-filter.php
--
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

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



[PHP] Re: Form to page force download

2006-04-21 Thread Rafael

Peter Lauri wrote:
[···]

1. Fill out a form on a web page
2. Lands on a thank you page and force a download of a pdf

Right now I solve this by outputting the thank you page and then using a
javascript to redirect to the download.php that consist of the following:

header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="eguide.pdf"');
readfile('http://www.thedomain.com/download/eguide.pdf'); 


Unfortunally it seams like some browsers blocks my javascript that redirects
to that address. If JavaScript is enabled, this works fine.

How would you solve this? Any method in PHP? I was hoping to be able to do
the thing that download.php does in the same file as the output of my thank
you page.


	So... why don't you do it that way?  I have a function similar to your 
code (for "sending" the file) and call it whenever I need it in the 
'main' page (no special page for download used)  You may want to try 
yourself

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

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



[PHP] Re: asociative array syntax

2006-04-21 Thread Rafael

Merlin wrote:

I would like to associate to 2 variables the same content.
Example:

'gm_GM', 'gm_CH' => array(

unfortunatelly this syntax does not work. It simply overwrites gm_GM
Any ideas on how to make this possible?


	'gm_GM' is not overwritten, do a  print_r($array)  to verify.  What 
you're telling PHP to do is to add a secuential index whose value is 
'gm_GM', then an asociative index 'gm_CH' whose value is an array.


If you want to assign the same value to both index, you need to simply 
do
  'gm_GM' => $value,
  'gm_CH' => $value,
or
  $array['gm_GM'] = $array['gm_CH'] = $value;
--
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

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



[PHP] Re: Preg_match() regex

2006-04-21 Thread Rafael
	As Joe implied with his link, the preg_* family is called PCRE (Perl 
Compatible Regular Expression), and that's because they accept a 
Perl-style regexp as a string, i.e. '/foo-foo/i' would do it.


Jeff wrote:

Regex pattern question here.  I need to match on "Foo-F00", "Foo-foo",
"foo-Foo".  I know in perl you can use the /i to specify "case
insensitive" matching.  Is there any such switch that can be used in
preg_match() in PHP?

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

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



[PHP] Re: unique array problem

2006-04-22 Thread Rafael
	If what you want is to have a continuos secuential array (i.e. 0=>x, 
1=>a, 2=>f) and there's no need for sorting the values, then you need 
array_values()[1]

[1] http://php.net/array-values

suresh kumar wrote:

I am facing one project in my project .
   
  this is my  code:
   
  a=array(0=>10,1=>10,2=>20,3=>30,4=>30,5=>40);

  b=array();
  b=array_unique($a);
  print_r($b); 
  o/p  getting from above code is  b[0]=10,b[2]=20,b[3]=30,b[5]=40;
   
  but i want the o/p be b[0]=10,b[1]=20,b[2]=30,b[3]=40;
   

>   i searched php.net .i am not able to fine any solution.i am breaking
>   my head for last  5 hours.i am waiting reply from any one
--
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

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



Re: [PHP] PHP Standard style of writing your code

2006-04-28 Thread Rafael

IMHO, vertical aligned brackets can be messy when nesting
relatively-small blocks (and seems to me like a lot of wasted space)
A couple of facts of my codding style:
- I tend to always use brakets, so I ignore the fact that single
  lines/actions can be written without brackets,
- I try not to let lines grow larger than about 100 cols (cannot
  be really done with strings and other thingies, and maybe that
  should remain in the old 80 cols, but it's too litle space), and
- I use a 4 space indentation, and that alone suffices for making
  a block stand clear enough

So, in my case, the code would be something like
  function foo( $x ) {
  // body...
  }
  ···
  $a = foo($b);

Chris W. Parker wrote:

So no matter what was actually typed, *I* would see:

function foo ($x) {
 //body
}

but some heretic who doesn't know any better would see:
function foo($x)
{
 //body
}

[···]

Setting aside the fact that you're completely wrong about your
preference... ;)

What, in your mind, is the advantage to putting the opening brace on
the same line as the function call, logic statement, etc.? (Btw, this
is a serious question!)

[···]
P.S.	What, in your mind, is the advantage of replying after quoting the 
original message and not before? :)

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

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



[PHP] Re: RegExp for preg_split()

2006-04-28 Thread Rafael

Try this (don't pay attention to the name):
  /**
   * @param string  $text
   * @returnarray
   * @since Sat Apr 29 01:35:37 CDT 2006
   * @authorrsalazar
   */
  function parse_phrases( $text ) {
  $arr_pzas = array();
  if ( preg_match_all('/(?(?=["\'])(["\']).+?\\1|\w+)/X',
  $text, $arr_pzas) ) {
  $arr_pzas = $arr_pzas[0];
  }
  return  $arr_pzas;
  } // parse_phrases()

Weber Sites LTD wrote:

Hi
 
I'm looking for the RegExp that will split a search string into search

keywords.
while taking " " into account.
 
From what I managed to find I can get all of the words into an array but I
would 
like all of the words inside " " to be in the same array cell.

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

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



Re: [PHP] PHP Standard style of writing your code

2006-04-28 Thread Rafael
	It's kind of ironic that you didn't split that big chunk of text into 
paragraphs, don't you think? ;)


	Anyway, yes, I was referring to visual space, we all know that is more 
clear the more you can see the code, that's why we don't let rows go 
insinely long (well, wide actually), and that also applies for the 
"vertical viewport" (rows also, not only columns)  That's why *I* find 
it a waste of (vertical) space.


	But, as we all know also, coding style is just that, a style, yet 
another matter of taste --of course, there are some basics that should 
always be present for the sake of clarity (such as indentation, 
comments, and an empty line here and there as logic-separator), or 
that's what I think, anyway --let's not discuss about this, wi'l ya?


Paul Novitski wrote:

IMHO, vertical aligned brackets can be messy when nesting
relatively-small blocks (and seems to me like a lot of wasted space)


I'm struggling to get my head around this concept of 'wasted space' with 
regard to software code.  What is it that's getting wasted, exactly?  If 
we printed our programs on paper it would be wasted trees (page-space) 
but I almost never do this and I don't know anyone who does except 
banks.  It could be seen as a waste of disk space, but only at the rate 
of a few bytes per code block, carriage return plus perhaps a couple of 
tabs.  What we must be talking about here is a waste of visual space.  
How does visual space get wasted?  Isn't it possible to waste something 
only if it's in finite supply?  I guess it's being wasted if it's 
something valuable that's not being used.  However, the urge to add 
whitespace to spread things apart is done with the intent of making code 
easier to read, so that seems like a use, not a waste.


OK, OK, I'll stop.  Think I'll go out and get wasted~

P.

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

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



Re: [PHP] PHP Standard style of writing your code

2006-04-29 Thread Rafael
	Thanks for your reply.  Paul Novitski already "talked" with me about it 
(in private), and my conclusions were...

-
	I guess that has something to do with the way *I* read my mails, since 
I'm usually aware what people are talking about (since I've wrote the 
one they're responding, or I've been following the thread)


	I think you have a pretty good reason, but I also think it doesn't work 
for me --since I have to skip the whole message I've already read, or 
what I wrote :)  Thanks for your answer (and so fast)

-
	I guess this is just one more of the too-many-already debatible points 
out there.  At the end, is a matter of taste, I can't see any as the 
right nor wrong option.


PS	I'd ask you a favor: do not include the email in the quotation, since 
these message are usually available (via http) in some sites, and having 
my email there makes a lot easier for me to get (even) more spam

PPS WTF is "IMALOOPHO"?

Porpoise wrote:
"Rafael"  wrote in message 
news:[EMAIL PROTECTED]


P.S. What, in your mind, is the advantage of replying after quoting the
original message and not before? :)

In an NG environment, it allows everyone to follow the logic and see 
clearly what is being replied to, in the correct context.


IMALOOPHO...

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

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



Re: [PHP] RegExp for preg_split()

2006-04-29 Thread Rafael
	LOL  It's interesting that you've taked your time and build that 
'summation', maybe the only thing is missing is the code itself ;)
Now, because you didn't add it, I had to check the different versions, 
and I agree with John Hicks, his suggestion seems to be the best one.


tedd wrote:

A summation of entries.

http://xn--ovg.com/a/parse.php

neat!
tedd

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

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



[PHP] Re: How do I make a HTML tree for a set of nodes?

2006-06-04 Thread Rafael
	Well, if you're asking for some recommendation on how to show it, I 
would suggest to use lists (either ordered -OL- or unordered -UL- 
depends on you), or maybe even data-lists (DL), so you would get

  +- parent 1
  |  +- child 1
  |  \- child 2
  +- parent 2
 \- sub-parent1
+- sub-child 1
\- sub-child 2
into something like
  
 parent 1
 
   child 1
   child 2
 

 parent 2
 
sub-parent 1

  sub-child 1
  sub-child 2

   
 

  

	Now, if you're asking for code, send what you've tried so far, and 
maybe someone will be able to help you (either correcting your code, or 
sending another way to do it)


Niels wrote:

I have a set of nodes. Each node has a parent and so the set can be thought
of as a tree. I want to show that tree somehow on a webpage, served by PHP.
I cannot use Dot/Graphwiz for various reasons. What I'm looking for is an
output of DIVs or tablecells, showing the nodes and their connections. It's
not a trivial task, IMO, but doable. Possibly somebody has already made
something similiar, but I can't find anything on Google. Can anybody point
me to helpful information?

--
Atentamente / Sincerely,
J. Rafael Salazar Magaña

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



[PHP] Re: Getting totals

2006-06-06 Thread Rafael
	Well, if I understood correctly, and the IP's first 3 segments are all 
of the same length, the you could do something like this (MySQL)

  SELECT
SUBSTRING(ip, 1, 11) AS ip,
COUNT(1) AS cantidad
  FROM tabla
  GROUP BY ip

	Now, if you don't intend to do this in SQL, then you could try some of 
the other suggestions.


Rob W. wrote:

Ok, Here is my next problem.

Inside my database, I have a list of ip's of about 10 blocks

192.168.100.0 all the way though 255 along with 192.168.101.0 though
255 and 192.168.102.0 though 255 and soforth

My problem is, is i'm trying to figure out a pattern to match so I
can count how many ip's are in each block and display them.

So far what I have gotten is a stristr match but it's not working
correctly. I have a variable that basically weed's out the last
digits of the ip it's self from help previously

So my code so far is:

if (stristr($block,$address)) { $count_ip++; }

$block would == 192.168.100 $address would == 192.168.100.0 - 255

Any help would be appricated.

--
Atentamente / Sincerely,
J. Rafael Salazar Magaña

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



Re: [PHP] Getting totals

2006-06-07 Thread Rafael
	I really doubt you need to use strstr() here, since it will return a 
string (_if_ the 'needle' is found in the 'haystack')[1], I guess you're 
looking for strpos() or something similar.


	Now, you said that you have this IPs on your database, so why don't you 
count the IPs directly on your database?  If the examples you gave are 
real and the first 3 segments of each IP are the same, then you could 
group your records, clasify and count them.  For example, if you were 
using MySQL, you can count them with something like


  SELECT
SUBSTRING(ip, 1, 11) AS ip
COUNT(1) AS counter
  FROM table
  GROUP BY ip
  ORDER BY ip ASC
*NOT tested

which should give you something like
  ip  | counter
 -+-
  192.168.100 |   1
  192.168.101 |   2
  ··· |   ···
  192.168.110 |  11

[1] http://php.net/strstr

Rob W. wrote:
Sorry for the miss understanding, That's the way the viarable will look, 
i'm putting it in as a viariable.


if (strstr($block,$address)) {
 $inc++;
}

- Original Message - From: "Richard Lynch" <[EMAIL PROTECTED]>
To: "Rob W." <[EMAIL PROTECTED]>
Sent: Tuesday, June 06, 2006 8:58 PM
Subject: Re: [PHP] Getting totals




Put quotes or apostrophes on the strings...
if (strstr('192.168.100','192.168.100.10')) {

On Tue, June 6, 2006 8:46 pm, Rob W. wrote:


if (strstr(192.168.100,192.168.100.10)) {
  $inc++;
}
echo "$inc";

That returns nothing. What am i still doing wrong?

- Original Message -
From: "Rabin Vincent" <[EMAIL PROTECTED]>
To: "Rob W." <[EMAIL PROTECTED]>
Cc: 
Sent: Tuesday, June 06, 2006 1:36 PM
Subject: Re: [PHP] Getting totals



On 6/6/06, Rob W. <[EMAIL PROTECTED]> wrote:


So far what I have gotten is a stristr match but it's not working
correctly. I have a variable that basically weed's out the last
digits of
the ip it's self from help previously

So my code so far is:

if (stristr($block,$address)) {
   $count_ip++;
}



You've got the parameters mixed up. strstr is (haystack,
needle) so you need strstr($address, $block). php.net/stristr.

--
Atentamente / Sincerely,
J. Rafael Salazar Magaña

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



[PHP] Re: How to re-order an array

2006-06-10 Thread Rafael
	Since you asked for some theory... theorically, you won't rely on 
javascript to prepare/validate/whatever some data to the server, that's 
what server-side scripts are for.
Note: you may use JS to make things quicker if possible, or to 
pre-digest the data, but you shall not rely entirely on JS.


	You say that not all browsers support the javascript functions you 
pretend to use, and that not all them support Ajax either.  That sounds 
just like saying that not all browser will have javascript enabled 
--that's why you shouldn't rely on javascript


	Although, this isn't a javascript list, why don't you send whatever you 
were trying to solve this issue? the code that uses JS functions not 
supported for all the browsers that will potentially run the script (as 
well as what these browsers are)  Most likely someone will be able to 
help you this way.


jekillen wrote:

Hello;
i'm scratching my head with a difficulty.
The situation is this.
A script begins with one indexed array (not associative) and one other 
indexed array

with the same values in a different order, the final order.
I want to create an interim array and progressively re order the array 
until it matches
slot for slot one of the original arrays. At this point the script is 
considered completed.
One important factor is that I'm looking to write this in javascript and 
the interim

array will be altered by the actions of a web page user.
Why am I asking the php list? Because I have a better chance of getting 
an answer
here. I'm not looking for help with javascript, specifically, just how 
one would go about
this task. Answer with php code and some theory if you wish and I will 
try to translate

it into javascript.
Some javascript functions I might use aren't supported in all the 
browsers that will

potentially run the script.
I might resort to using Ajax and let php keep track for me. But, then 
again not all

browsers will do the Ajax either (as I understand it).

--
Atentamente / Sincerely,
J. Rafael Salazar Magaña

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



Re: [PHP] Re: How to re-order an array

2006-06-11 Thread Rafael

jekillen wrote:
[···]
You misunderstand my question. I know the limitations of javascript. The 
server won't respond to events registered in the browser. I write tons 
of forms that are all processed
by the client with javascript. I have written ferocious regex filters 
that hack apart form submissions before they even leave the client. I 
have set it up so if the client doesn't
have javascript enabled, the form won't submit if it is going to the 
server. That is why as much as possible I shift form processing to the 
client as much as possible, for
security and to off load work to the client. I use php to dynamically 
write js files when necessary, anticipating what data will be requested.


	I didn't (misunderstood), what I told you is that you cannot rely on 
javascript (actually, that would be "anything coming from the client") 
You need to do validate on the server, and it doesn't matter if you 
already did it on the client or not (simply because you cannot know that 
for sure)


This is a problem that is more a matter of programming theory. I have 
posted to javascript forums and lists and have never got a response.
I will be applying this to dhtml which the server won't and can't do but 
may help things along with Ajax.
Just a simple suggestion about how to reorder arrays if you have a few 
words and suggestions. I'm not looking for free training.
I have been learning and using php and javascript for some five years 
and have developed my own approach to testing and debugging
and such. So I am not really a newby. I have made the dumb mistakes of 
asking for help from forums and lists when it was just a dumb
syntax error that I couldn't expect anyone but my self to find, which i 
have in 99.9% of the cases. Some times it is nice to get some
quick help from a list and I will try to return the favor when ever 
possible to the next person looking for help that I have some answers for.


	Well, I asked you for the actual (JS) code you're using (the one that 
didn't work in all the intended browsers), that way someone might be 
able to help you (I will if I can)

--
Atentamente / Sincerely,
J. Rafael Salazar Magaña

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



Re: [PHP] Re: How to re-order an array

2006-06-12 Thread Rafael

jekillen wrote:
[···]
Well, I asked you for the actual (JS) code you're using (the one 
that didn't work in all the intended browsers), that way someone might 
be able to help you (I will if I can)


Array.push(), Array.pop(), Array.shift(), Array.unshift().


	Ok, so what are your intended browsers?  According to what I found, 
these functions are part of ECMAS 3 standard, and are available in FF 
1.0, Netscape 4, e IE 5.5 (unshift until IE 6) --as always, M$ gives the 
problems.


You might try to implement them yourself, such as...
  // "object detection" for shift function
  if ( undefined == Array.prototype.shift ) {
Array.prototype.shift = function( ) {
  var  val = this[0];
  for ( var  i = 0;  i < this.length - 1;  i ++ ) {
this[i] = this[i + 1];
  }
  this.length --;
  return  val;
} // shift()
  }
  // "object detection" for unshift function
  if ( undefined == Array.prototype.unshift ) {
Array.prototype.unshift = function( ) {
  var  args = arguments,
   len  = this.length + args.length;
  this.length = len;
  for ( var  i = len - 1;  i >= args.length;  i -- ) {
this[i] = this[i - args.length];
  }
  for ( i = 0;  i < args.length;  i ++ ) {
this[i] = args[i];
  }
} // unshift()
  }

  var  x = new Array( 'z', 'b', 'c', 'd' ),
   y = null;
  document.write("→ "+ x.toString() +"\n");
  y = x.shift();
  x.unshift('A', 'a');
  document.write("⇒ "+ y +" ⇒ ["+ x.toString() +"]");

Note: tested only in Fx 1.5.0.3 (as _shift & _unshift) with secuential
  arrays (and not associative/hash arrays)

I thought that if I used Ajax, php could use its push and pop, shift and 
unshift functions, but not all browsers support the asymetric requests.


	Well, that seems too complex to solve your problem, but if you want to 
try it, you may use the same "object detection" above and implement 
those methods with PHP (e.g. unshift in IE 5.5, or all of the functions 
you mentioned in IE 5.0)


I do screen in the server. But I force the user to have javascript 
enabled and force the form to submit using javascipt, and have a unique 
id as a javascript variable
that is sent along with the form in a hidden field to identify the 
source of the form data. I never use get requests unless they are 
appended to anchor tags, even
in  forms that are not processed by the server (I.E. running javascript 
code with user supplied arguments to functions via form fields, in which 
case an action attribute

isn't even necessary, and like wise a post or get method).


	It's basically the same problem, you shouldn't rely on javascript for 
your page to actually do something.  If I don't have JS enabled (for 
whatever the reason) I won't be able to do anything on it.  JS should be 
used only to _add or complement_ functionality.

--
Atentamente / Sincerely,
J. Rafael Salazar Magaña

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



[PHP] Re: preg_replace \\1 yIKES!

2006-06-13 Thread Rafael

Capitalize the first letter of a word: ucwords()[1]

	Now, if it's just for practice, then you need a little change in you 
code, since  strtoupper('\\2')  will give '\\2' (i.e. does nothing) and 
the letter will remain the same.  One way to do it would be

  $text = 'hello world (any ...world)';
  echo  preg_replace('/\b(\w)/Xe', 'strtoupper("\\1")', $text);
check the manual[2] for more info...

[1] http://php.net/ucwords
[2] http://php.net/manual/en/reference.pcre.pattern.syntax.php
http://php.net/manual/en/reference.pcre.pattern.modifiers.php

sam wrote:

Wow this is hard I can't wait till I get the hang of it.

Capitalize the first letter of a word.

echo preg_replace('/(^)(.)(.*$)/', strtoupper('\\2') . '\\3', 'yikes!');
// outputs yikes!

Nope didn't work.

So I want to see if I'm in the right place:

echo preg_replace('/(^)(.)(.*$)/', '\\1' . '-' . strtoupper('\\2') .  
'-' . '\\3', 'yikes!');

//outputs -y-ikes!

So yea I've got it surrounded why now strtoupper: Yikes!

--
Atentamente / Sincerely,
J. Rafael Salazar Magaña

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



[PHP] Re: Setting headers for file download

2006-06-13 Thread Rafael

I use something like this...
  $file_len = filesize($file_name);
  $file_ts  = filemtime($file_name);
  header('Content-Type: application/x-octet-stream'); // none known
  header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  header('Last-Modified: '. gmdate('D, d M Y H:i:s', $file_ts) .' GMT');
  header('Content-Disposition: attachment; filename="'. 
basename($file_name) .'"');

  header("Content-Length: $file_len");
  readfile($file_name);


Peter Lauri wrote:

Best group member,

This is how I try to push files to download using headers:

header("Content-type: $file_type");
header("Content-Disposition: attachment; filename=$filename"); 
print $file;


It works fine in FireFox, but not that good in IE. I have been googled to
find the fix for IE, but I can not find it. Anyone with experience of this?

Best regards,
Peter Lauri


--
Atentamente / Sincerely,
J. Rafael Salazar Magaña

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



[PHP] errata

2006-06-13 Thread Rafael
Now, if it's just for practice, then you need a little change in you 
code, since  strtoupper('\\2')  will give '\\2' (i.e. does nothing) and 
the letter will remain the same.


	I meant, since *strtoupper('\\2')* is evaluated _before_ being included 
in the string (used as replacement), i.e...

  preg_replace('/(^)(.)(.*$)/', strtoupper('\\2') . '\\3', 'yikes!');
is evaluated as
  preg_replace('/(^)(.)(.*$)/', '\\2\\3', 'yikes!');
since *strtoupper('\\2')* => *'\\2'*, that's why I said it does nothing.

	In the code sent, *strtoupper()* is passed as a (literal) string which, 
combined with the "e" modifier (at the end of the expression), gives the 
effect you were looking for (i.e. the "replacement string" is evaluated 
--as code-- before it actually replaces the string found)

--
Atentamente / Sincerely,
J. Rafael Salazar Magaña

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



Re: [PHP] Re: Setting headers for file download [medium]

2006-06-14 Thread Rafael

Barry wrote:

Peter Lauri schrieb:

Ok, my knowledge about HTTP is not the best. But how can you send three
different content-type headers? :)


There are not so different at all.
Just giving the browser the job to download that thing.

Every browser likes to interpret every content-type like he wants to.
They ignore mostly every type they dislike.


	According to the manual, header() will replace previous "similar 
headers" with the new one sent, which would be

  header("Content-Type: application/download");

"The optional replace parameter indicates whether the header should 
replace a previous similar header, or add a second header of the same 
type. By default it will replace, but if you pass in FALSE as the second 
argument you can force multiple headers of the same type"

[1]http://php.net/header

	As for the value of Content-Type it doesn't matter, you only have to 
specify an unknown (MIME) type so the browser won't know what to do with 
it, hence forcing to download the file.


	As minor notes (after reading a bit the RFC)... "Expires" is expected 
to be a date, not a number, and "Pragma" value conflicts with 
Cache-control, since...

   public
  Indicates that the response MAY be cached by any cache, even if it
  would normally be non-cacheable or cacheable only within a non-
  shared cache. (See also Authorization, section 14.8, for
  additional details.)

	Also, it seems we're given a wrong use for "must-revalidate" (me 
included), that or I misunderstood the RFC documentation --I didn't even 
found "pre-check" & "post-check".  Content-Disposition is not part of 
the HTTP standard and Content-Transfer-Encoding is ignored, since both 
seem to be for e-mail usage (LOL) --and it's possible values are 
"quoted-printable" o "base64"--.  Finally, "Content-Length" and 
"Content-Type" seem to apply only if "had the request been a GET".


	Interesting what you learn reading the RFCs, too bad they're too long 
and sometimes not that clear.

RFC: http://www.faqs.org/rfcs/rfc2616
--
Atentamente / Sincerely,
J. Rafael Salazar Magaña

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



[PHP] Re: can I do this: update table while selecting data from table?

2006-06-14 Thread Rafael
	As far as *I* know, yes, the SELECT statement is excuted at that 
particular moment, and any further execution will be independant of your 
initial (SELECT) query.  Was there any problem?


[EMAIL PROTECTED] wrote:

Am I allowde to do this:

$query = mysql_query("SELECT member_id, member_name FROM members");
while($result = mysql_fetch_array($query))
{
  if(empty($result['member_name']))
  {
mysql_query("UPDATE members SET member_name = 'N/A' WHERE member_id =
".$result['member_id']."");
  }
}

As far as I know, after "SELECT" query, data are in buffer and I AM able
to connect to the same table and do UPDATE, right?

Thanks

-afan

--
Atentamente / Sincerely,
J. Rafael Salazar Magaña

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



[PHP] Re: Replacing text with criteria

2006-06-15 Thread Rafael

Try with
  preg_replace('/\d(?!(?>\d*)\))/X', '*', $phone)
wich would be a bit more efficient than
  preg_replace('/\d(?!\d*\))/X', '*', $phone)

Jeff Lewis wrote:

I have been working on a script to parse a CSV file and in the process I
clean out a lot of the garbage not needed but I am a bit stumped on one
aspect of this file. It's a list of over 3000 contacts and I'm trying to
mask a lot of the information with *.
 
So as I loop through this list I am checking the array elements as if I find

a phone number (555) 555-1212 (I was searching for the (555)) I want to
convert it to (555) ***-
 
For fields not containing an area code, I wanted any text to be replaced by

an * except for the first and last letter in the element.
 
I'm stumped and was hoping that this may be something horribly simple I'm

overlooking that someone can point out for me.

--
Atentamente / Sincerely,
J. Rafael Salazar Magaña

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



[PHP] Re: comparing a string

2006-06-20 Thread Rafael

(inline)

Ross wrote:
I have a quiz where the ansers are held in a array called $correct answers. 
When I compare the string


if  ($_REQUEST['x']= $correct_answers[$page-1]) {

with a double == the answer is always correct with the single = it is always 
wrong.


	A single "=" it's an assignment, not a comparison; and though it 
sometimes work, you shouldn't compare strings with "==", but using 
string functions, such as strcmp()...  or similar_text(), etc.


when I echo out the posted answer and the value from the answers arrray they 
are correct.


echo "post equals".$_POST['x']." corect answer 
is".$correct_answers[$page-1];

--
Atentamente / Sincerely,
J. Rafael Salazar Magaña

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



[PHP] Re: comparing a string

2006-06-20 Thread Rafael

(inline)

Adam Zey wrote:

Rafael wrote:
A single "=" it's an assignment, not a comparison; and though it 
sometimes work, you shouldn't compare strings with "==", but using 
string functions, such as strcmp()...  or similar_text(), etc.


This is PHP, not C. Operators such as == support strings for a reason, 
people should use them as such.


	You shouldn't rely on what other languages do, but the one you're 
working with; PHP has no explicit data-types and manages strings as PERL 
does.  Just as you say there's a reason why "==" supports strings, 
there's also a reason (or more) for strcmp() to exists --it's just safer 
to use strcmp() instead of "==", e.g: 24 == "24/7"


If you need to ensure type, (so that 0 == "foo" doesn't return true), 
then you can use ===.


Using a function call that does more than you need when there is an 
operator to achieve the same goal is bad advice. 


	I think you haven't encounter a "special case" to make you understand 
"==" does NOT have the same behaviour as strcmp()  It's just like the 
(stranger) case of the loop

  for ( $c = 'a';  $c <= 'z';  $c ++ )
  echo  $c;

Not to mention the fact 
that it leads to harder to read code. Which of these has a more readily 
apparent meaning?


if ( strcmp($foo,$bar) == 0 )

if ( $foo === $bar )


	That might be true, either way you need to know the language to 
understand what the first line does and that the second isn't a typo.

--
Atentamente / Sincerely,
J. Rafael Salazar Magaña

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



[PHP] Re: comparing a string

2006-06-21 Thread Rafael

(inline --and last post on this thread)

Adam Zey wrote:

Rafael wrote:

(inline)

Adam Zey wrote:

Rafael wrote:
A single "=" it's an assignment, not a comparison; and though it 
sometimes work, you shouldn't compare strings with "==", but using 
string functions, such as strcmp()...  or similar_text(), etc.


This is PHP, not C. Operators such as == support strings for a 
reason, people should use them as such.


You shouldn't rely on what other languages do, but the one you're 
working with; PHP has no explicit data-types and manages strings as 
PERL does.  Just as you say there's a reason why "==" supports 
strings, there's also a reason (or more) for strcmp() to exists --it's 
just safer to use strcmp() instead of "==", e.g: 24 == "24/7"


Safer, yes. And it'd be even better to do 24 === "24/7", in which case 
you don't need a function call, it's probably faster (I'd imagine that 
comparing equality is faster than finding out HOW close it is like 
strcmp does), and as I mentioned, easier to read.


	The only possible values of strcmp() are: 1, 0 & -1.  Hence, basically 
both are doing the same, the difference would be the value they return, 
one returns a boolean, and the other an integer --strcmp() doesn't 
compare "HOW close it is" one string from the other, you might be 
talking about levenshtein(), similar_text(), soundex(), etc.


	As for the speed, it would be "===" (0.0007), "==" (0.0008) and lastly 
strcmp() (0.0012) in a quick test with 1000 comparisons.  So yes, an 
operator is faster than a function call (kind of obvious), but my point 
was to use strcmp() instead of any of the operator based solely on 
experience with string comparisons, that was all, and I certainly don't 
think that would be a bad advice, but I think that say something like 
"use the operator, it's faster" it is a bad advice, since you're not 
explaining how does it work (e.g. "automatic casting") which could led 
to unexpected results, don't you think?  Anyway, that's something that 
you find only in "special cases".


If you need to ensure type, (so that 0 == "foo" doesn't return true), 
then you can use ===.


Using a function call that does more than you need when there is an 
operator to achieve the same goal is bad advice. 


I think you haven't encounter a "special case" to make you 
understand "==" does NOT have the same behaviour as strcmp()  It's 
just like the (stranger) case of the loop

  for ( $c = 'a';  $c <= 'z';  $c ++ )
  echo  $c;


I didn't say that it had the same behaviour, only the same goal; finding 
out if two strings are equal. strcmp does MORE than that, it also finds 
out how CLOSE they are. You almost never need that information, in which 
case you're wasting processing time with a function call that does 
something that you don't need. Come on, face it, how many times have 
done anything with strcmp's return value OTHER than checking that it's 
zero? I bet the cases are fairly rare.


	I already "talked" above about what strcmp() does.  As for the cases 
that I've used strcmp() to know if two strings are equal, *obviously* 
they're more than those I've used strcmp() to see what string is 
"bigger" than the other ("custom-sorting" is the only case I remember)


Not to mention the fact that it leads to harder to read code. Which 
of these has a more readily apparent meaning?


if ( strcmp($foo,$bar) == 0 )

if ( $foo === $bar )


That might be true, either way you need to know the language to 
understand what the first line does and that the second isn't a typo.


=== is a basic operator. One has to assume that somebody writing code is 
at least familiar with the basic operators. If not, well, asking them to 
know what the function strcmp does and what it means when it returns 
zero is just as onerous. If not more so. And again, strcmp wastes time 
calculating information we don't NEED.


	"===" is not that of a basic operator, not even in PHP.  And "==" looks 
like a typo for those new to C (or similar), so they have to *learn* 
what does it mean, the same goes for strcmp() --which may be even more 
familiar than "===" for some people (me included)

--
Atentamente / Sincerely,
J. Rafael Salazar Magaña

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



[PHP] Re: Parsing HTML

2006-02-16 Thread Rafael
	If all you want is to "parse" HTML code, then you could treat it as 
XML, of course, that would assume that the sites are all well XHTML 
formed.  Other than that, I can only thing on PCRE.


Boby wrote:

I need to extract news items from several news sites.

In order to do that, I need to parse the HTML data.

I know how to use Regular Expressions, but I wonder if there are other 
ways to do that.

--
Atentamente,
J. Rafael Salazar Magaña
Innox - Innovación Inteligente
Tel: +52 (33) 3615 5348 ext. 205 / 01 800 2-SOFTWARE
[EMAIL PROTECTED]
http://www.innox.com.mx

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



[PHP] Re: A quick Regex query

2006-02-16 Thread Rafael

phplists wrote:

I am using the following:
[0-9]{4} [A-Za-zÅØ]{2,20}

to extract data like:
1000 Øslo

How can I alter the above to limit to ONLY 4 digits, or in other words 
exclude:

11000 Beograd

Please note that what I am extracting from is NOT at the begining of a 
line, so I can't use the ^ first.


	Well, it depends what "usually is" (can be) before what you want to get 
and the regex family your using.  If it's PCRE, you may try something 
like "\b\d{4} [A-Za-zÅØ]{2,20}"  \b = "word boundary", it's basically 
a word separator and it's not included in the result you get (since it's 
more a "position" rather than a "string")


Also, you may notice a couple of 'special' characters in my expression 
'Å + Ø'  By putting them in they seem to work fine, but is this the 
best way of doing it?


	I think it is.  IIRC what you define in a "class" (i.e. between 
square-brackets) is quite fast; e.g. "[ab]" fastest than "(a|b)", is 
that what you were asking?

--
Atentamente,
J. Rafael Salazar Magaña
Innox - Innovación Inteligente
Tel: +52 (33) 3615 5348 ext. 205 / 01 800 2-SOFTWARE
[EMAIL PROTECTED]
http://www.innox.com.mx

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



Re: [PHP] "!" in front of a variable?

2006-02-17 Thread Rafael

I took me a little while to notice that it wasn't a function 
declaration :p

	It's just as Jay said, it's calling "function" with those arguments, 
where '!$var2' extends to '!(bool)$var2' or "treat/cast this value as/to 
boolean, and pass it's inverted value" or "NOT $var2".


Jay Blanchard wrote:

[snip]
I've got some code from someone else I've inherited and need to sort out
some problems with.  The programmer that wrote it originally was much
better than I and programmed a little over my head to say the least.

One function that I've come across that has 5 variables as input:

function($var1,$var2,!$var2,$var3->cc,$var3->bcc);

The question I have is on the 3rd input variable, what does the "!" in
front of $var2 do to that variable?
[/snip]

Hmmm. Looks like a weird mistake, to be sure. If $var2 is boolean it should
pass the opposite of its current state. Is $var2 a boolean? It is being
passed twice here, once AS and once AS NOT.

--
Atentamente,
J. Rafael Salazar Magaña
Innox - Innovación Inteligente
Tel: +52 (33) 3615 5348 ext. 205 / 01 800 2-SOFTWARE
[EMAIL PROTECTED]
http://www.innox.com.mx

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



[PHP] Re: menu Q

2006-02-17 Thread Rafael
	I use Fx 1.5.0.1 and Opera 9-prev2 and everything seems to be Ok.  The 
select it's inside a form, and my guess is that you haven't set any 
padding/margin for that form, so try adding something like

  FORM {
padding: 0;
margin:  0;
  }

	By the way, this questions should not be here, what Kim posted was a 
really better place to post it: http://www.css-discuss.org

--having said that, I must confess I thought I was reading a message
  from that list, so maybe you got confused as well?

William Stokes wrote:
I have a  menu on a header bar on my page. The header bar is 20px 
high. The menu, code and style below, works ok on Opera but not in Ie6 or 
Firefox. In these browsers the menu 'streches' the bar height so that the bg 
image starts repeating itself. (looks nasty) It's almost like the menu 
prints one 'invisble' or empty row beneath the menu so that the header bar 
becomes about 30 or 35px high. Any ideas?



[···]

$sql="SELECT * FROM x_table ORDER BY sorter ASC";
$result=mysql_query($sql);
$num = mysql_num_rows($result);
$cur = 1;
print "";
print "onChange=\"javascript:goToURL()\">";

print "Valitse joukkue:";
while ($num >= $cur) {
$row = mysql_fetch_array($result);
$jouk_nimi = $row["jouk_nimi"];
$team_id = $row["jouk_id"];
print "$jouk_nimi";
$cur++;
}
print "";
print "";


StyleSheet:

#menu{
 height: 18px;
 font-family: Arial, Helvetica, sans-serif;
 font-size: 12px;
 font-weight: bold;
 text-align: left;
 background-color: #CC;
 BORDER-RIGHT: #FF 1px solid;
 BORDER-TOP: #FF 1px solid;
 BORDER-LEFT: #FF 1px solid;
 BORDER-BOTTOM: #FF 1px solid;
 COLOR: #FF;
}

--
Atentamente,
J. Rafael Salazar Magaña
Innox - Innovación Inteligente
Tel: +52 (33) 3615 5348 ext. 205 / 01 800 2-SOFTWARE
[EMAIL PROTECTED]
http://www.innox.com.mx

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



[PHP] Re: "isset" or "array_key_exists"?

2006-02-18 Thread Rafael
	After a little test, although the results are not conclusive, I would 
say that isset(), and also that array_key_exists() may even use isset() 
(or similiar) internally as a first step -let's remember that isset() 
only does a "fast search" and it returns FALSE if the value is NULL; on 
the other hand, array_key_exists() returns TRUE even if the value is 
NULL-  I said this (as an hypotesis) because the difference in time when 
the key exists and when it doesn't is quite big, sometimes about 10 
times slower.


	The script I used to test it was this (it is assumed that any "extra" 
operation affected both loops equally)

 array( 1 => -1 ) );
$num_oprs = 1000;


$start= micro_time();
for ( $i = 0;  $i < $num_oprs;  $i ++ ) {
if ( isset($arr_test['key'][1]) ) ;
}
echo  'isset: ', micro_time() - $start, "\n";


$start = micro_time();
for ( $i = 0;  $i < $num_oprs;  $i ++ ) {
if ( array_key_exists(1, $arr_test['key']) ) ;
}
echo  'array_key_exists: ', micro_time() - $start, "\n";



function micro_time( ) {
return  preg_replace('/^0(\.\d+) (\d+)$/X',
 '$2$1', microtime());
}

 ?>

Nikolay Rastegaev wrote:

Please, answer:

what construction works faster:

   if (  isset ( $result [$i] ["key"] )  )
   {    do something;   }

or

   if (  array_key_exists ( "key", $result [$i] )  )
   {do something;   }

?

--
Atentamente,
J. Rafael Salazar Magaña
Innox - Innovación Inteligente
Tel: +52 (33) 3615 5348 ext. 205 / 01 800 2-SOFTWARE
[EMAIL PROTECTED]
http://www.innox.com.mx

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



Re: [PHP] Re: "isset" or "array_key_exists"?

2006-02-18 Thread Rafael
	Actually, it doesn't have much sense that it creates a variable (or 
index), though it had sense why wouldn't be so easily detected, so I 
printed the array after the loops and there's no new keys.  I think that 
if that was the case, it was definitely a bug that has been corrected 
(PHP 4.4.0)

*Note: I guess that's because isset() is not a function, but a keyword

	That was very ilustrative Rob, thanks for the info (it's the kind of 
thing I shouldn't forget)


Satyam wrote:
[···]

isset is a keyword in PHP
array_key_exists() is a function.

Keywords are much faster than functions due tot he overhead functions
occur for setting up the stack.

If you don't care about null values, use isset(). If you do, use
array_key_exists().

The reason isset() doesn't return true for null entries has been
described in the past. The official stance was that null is not a value.


[···]


Accessing a non-existing element, doesn't create it? Thus, using isset 
to evaluate whether an element exists creates it, though with a null 
value.  If you make a first pass on the array with isset, a second pass 
with array_key_exists would give true for all of them though isset would 
give the same results as in the first pass.  I think this happened to me 
once when I went through an array with isset or isempty or some such to 
make some calculations and then on the second pass, when I printed it, I 
got lots of empty cells that were created empty in the first pass.

--
Atentamente,
J. Rafael Salazar Magaña
Innox - Innovación Inteligente
Tel: +52 (33) 3615 5348 ext. 205 / 01 800 2-SOFTWARE
[EMAIL PROTECTED]
http://www.innox.com.mx

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



[PHP] Re: regular pattern to match åäö

2006-02-18 Thread Rafael

Just a couple of questions/points to make all clear:
a) are you aware that the "^" at the beggining inverts its meaning?
b) if you want to allow (or "not fail with") "-", put it as the fist
   (or last?) character of the class, since it is used to define
   ranges, and this avoids misinterpreting its meaning
c) what regex family functions are you using and what would be the
   complete expression?

Patrick wrote:

im trying to get my regular pattern to allow åäöÅÄÖ but it refuses to,
i have something like this:

[^a-zA-ZåäöÅÄÖ0-9-_ ]

But this dosent seem to work, anyone got any ideas?

--
Atentamente,
J. Rafael Salazar Magaña
Innox - Innovación Inteligente
Tel: +52 (33) 3615 5348 ext. 205 / 01 800 2-SOFTWARE
[EMAIL PROTECTED]
http://www.innox.com.mx

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



[PHP] Re: Request for views on ASP/PHP/ASP.NET - please!

2006-02-20 Thread Rafael
	Well, I would like to know what conclusion you got, so if possible let 
me know when you have enough data/finished you work.


Simon O'Beirne wrote:

Hi guys,

A bit of an odd request.  I'm in my third and final year at university, and
part of an assignment requires obtaining developers' perspective on web
languages.

If anyone has done at least one of the languages in the subject title
(ASP/ASP.NET/PHP), I would be eternally grateful if you could pop to (and
also send any other web developers you know to)

http://www.coralsystemsolutions.co.uk/uni

Theres a maximum of 14 short questions (depending on answers to the other
questions), all optional, just fill out as much as you can be bothered with,
then click submit a few times until its saved.

Thank you very much in advance!

Simon 

--
Atentamente,
J. Rafael Salazar Magaña
Innox - Innovación Inteligente
Tel: +52 (33) 3615 5348 ext. 205 / 01 800 2-SOFTWARE
[EMAIL PROTECTED]
http://www.innox.com.mx

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



Re: [PHP] String parsing help

2003-08-20 Thread Rafael Zanetti
$vector=split( " ", $string, );
$City=$vector[0];
$State=$vector[1];
$Zip=$vector[2]:

This will not work because there cases where the city name have more than 1
word

you must get from end-to-begining

i can't think about it now, but it's a tip anyway


> $vector=split( " ", $string, );
>
>
> $City=$vector[0];
> $State=$vector[1];
> $Zip=$vector[2]:
>
> - Original Message - 
> From: "Matt Matijevich" <[EMAIL PROTECTED]>
> To: "<" <[EMAIL PROTECTED]>
> Sent: Wednesday, August 20, 2003 5:11 PM
> Subject: [PHP] String parsing help
>
>
> > I have have a string that I need to split into 3 different variables:
> > City,State, and Zip.  Here is a couple examples of the strings I need to
> > parse:
> >
> > ANCHORAGE  AK  99507-6420
> > JUNEAU  AK  99801
> > NORTH LITTLE ROCK  AR  72118-5227
> >
> > Does anyone have an idea how I could slit this into the appropriate
> > variables, maybe some kind of regular expression?  I cant use the space
> > character to split the data because some of the city names have spaces
> > in them.
> >
> > -- 
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
>
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


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



[PHP] preg_replace_callback

2002-07-17 Thread Rafael Fernandes

First, sorry for my elementary english...
I need a function made for PHP3 that works like preg_replace_callback...
Sugestions???
-- 
Rafael Fernandes
WebDeveloper - Aleph TI Ltda. / Matrix Internet Provider
E-Mail: [EMAIL PROTECTED]
Uin: 5551571

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




[PHP] Lines

2001-04-24 Thread Rafael Faria



Hey Guys,
it's my first post on this list, and my doubt is...

how can i take a file.txt and

1 - know how many lines i have in this text
2 - print line 5 until 10

?

can someone help me?





---

[ r a f a e l   f a r i a] _
[EMAIL PROTECTED]
WebMaster Universo Online - http://www.uol.com.br
Phone # +55 11 3038-8665


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Lines

2001-04-24 Thread Rafael Faria

But how can i put into a var $total the total lines that i have into the file?

Rafael

>f you use the file() function to open up the file, it will put each line 
>of the file into an array.  At that point you can say:
>
>for($i=5;$i<11;$i++){
>
>print $myFile[$i];
>
>}
>
>
>Michael
>
>
>Rafael Faria wrote:
>
>>
>>
>>Hey Guys,
>>it's my first post on this list, and my doubt is...
>>
>>how can i take a file.txt and
>>
>>1 - know how many lines i have in this text
>>2 - print line 5 until 10
>>
>>?
>>
>>can someone help me?
>>
>>
>>
>>
>>
>>---
>>
>>[ r a f a e l   f a r i a] _
>>[EMAIL PROTECTED]
>>WebMaster Universo Online - http://www.uol.com.br
>>Phone # +55 11 3038-8665
>>
>
>
>

---

[ r a f a e l   f a r i a] _
[EMAIL PROTECTED]
WebMaster Universo Online - http://www.uol.com.br
Phone # +55 11 3038-8665


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] IRC CHAT

2001-04-24 Thread Rafael Faria

 Hi again,
have somewhere that i can find a chat that connect with irc server?



---

[ r a f a e l   f a r i a] _
[EMAIL PROTECTED]
WebMaster Universo Online - http://www.uol.com.br
Phone # +55 11 3038-8665


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Lines

2001-04-25 Thread Rafael Faria

I should tell you that the "text file" is an htm that i have to print 
withou the header "" and footer ""

:PP

Rafael

>I know, it was already answered before me (you),
>
>I just though that an SQL database is a good advice for these who are trying
>to do this kind of jobs.
>It is obvious that the reason to use this function is to manage a stored
>data in files.
>then why not a database, if possible?
>
>
>Sincerely,
>
>  Maxim Maletsky
>  Founder, Chief Developer
>  PHPBeginner.com (Where PHP Begins)
>  [EMAIL PROTECTED]
>  www.phpbeginner.com
>
>
>
>-Original Message-
>From: Jason Murray [mailto:[EMAIL PROTECTED]]
>Sent: Wednesday, April 25, 2001 4:52 PM
>To: Maxim Maletsky; 'Rafael Faria'; [EMAIL PROTECTED]
>Subject: RE: [PHP] Lines
>
>
> > > it's my first post on this list, and my doubt is...
> > >
> > > how can i take a file.txt and
> > >
> > > 1 - know how many lines i have in this text
> > > 2 - print line 5 until 10
>
> > Is there any chance for you to use a database?
> > these thing would become MUCH, MUCH easier.
>
>Actually, this is really easy without using a database.
>
>1.$filename = "/path/to/file";
>   $filedata = file($filename);
>   $linesinfile = count($filedata);
>?>
>
>2.$startline = 5;
>   $stopline = 10;
>
>   for ($i = $startline; $i < $stopline; $i++ )
>   {
> echo $filedata[$i-1];
>   }
>?>
>
>(Use $i-1 because the first line is actually "0").
>
>Jason

---

[ r a f a e l   f a r i a] _
[EMAIL PROTECTED]
WebMaster Universo Online - http://www.uol.com.br
Phone # +55 11 3038-8665


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Upload a File

2001-04-25 Thread Rafael Faria


>Hey Guys,

i'm here thinking what i did wrong.can u guys help me?

i did 2 ways to upload a file and none of them work fine! :/

first way
$folder = "/tmp";
if(!copy($MyFile,$folder.$MyFile)){
  echo "can't copy";
} else {
  echo "work it!";
}

second way

$folder = "/tmp";

$dest = $folder."/".$MyFile_name;
if(!move_uploaded_file($MyFile, $dest)) {
   echo "can't copy!";
   exit;
 }



so. can someone help me please? i just have to make it to finish my job :/

thanks




---

[ r a f a e l   f a r i a] _
[EMAIL PROTECTED]
WebMaster Universo Online - http://www.uol.com.br
Phone # +55 11 3038-8665


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Upload a File

2001-04-25 Thread Rafael Faria

i tried:
if (!move_uploaded_file($MyFile,"/home/vacamarela/public_html/rafael")) {
 echo "can't copy";
 exit;
}

and retur "can't copy"

my form is




:/

Rafael




>Acesso fácil, rápido e ilimitado? Suporte 24hs? R$19,90?
>Só no AcessoBOL. http://www.bol.com.br/acessobol/
>
>
>move_uploaded_file($newfile,"/complete/path/to/move/file/to");
>
>My form variable for the file was called "newfile".  That should help.  It
>is very nice, just use it instead of copy and uyou should be good.  Good
>luck.
>
>+---+
>|   |
>|  If Yoda so strong in force is,   |
>| why words in proper order he cannot put?  |
>|   |
>+---+
>|   |
>+---+
>| Daniel J. Cleveland   |
>|   e-mail: [EMAIL PROTECTED]|
>+---+

---

[ r a f a e l   f a r i a] _
[EMAIL PROTECTED]
WebMaster Universo Online - http://www.uol.com.br
Phone # +55 11 3038-8665


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Count....

2001-04-25 Thread Rafael Faria

I'm doing a seach function... everything is okbut i wanna put something 
like "Use more specific terms" when the search don't have anything to 
show. but i can't do that can someone helpme?

i'm doing that!
=

 $query = mysql_query("select * from Newsletter_Members where 
Newsletter_Members.email like '%$search%' order by id");

  while ($row = mysql_fetch_row($query)) {

 echo "\n";
 echo "\n";
 echo " $row[0] \n";
 echo " mailto:$row[1]>$row[1] \n";
 echo "Editar\n";
 echo "\n";

  }

===

how can i make if doen't match anything say "it doen't match anything" ?






---

[ r a f a e l   f a r i a] _
[EMAIL PROTECTED]
WebMaster Universo Online - http://www.uol.com.br
Phone # +55 11 3038-8665


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] MP3

2001-04-27 Thread Rafael Faria



Have some way to make a script to get the info of mp3 file? like ID3 tag?

---

[ r a f a e l   f a r i a] _
[EMAIL PROTECTED]
WebMaster Universo Online - http://www.uol.com.br
Phone # +55 11 3038-8665


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] What's wrong?

2001-05-01 Thread Rafael Faria



What's wrong with my php file?













 
   File
   
 






---
---

[ r a f a e l   f a r i a] _
[EMAIL PROTECTED]
WebMaster Universo Online - http://www.uol.com.br
Phone # +55 11 3038-8665


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] IMAGE

2001-05-01 Thread Rafael Faria



Hy guys

how can i know the width and height of an image?


---

[ r a f a e l   f a r i a] _
[EMAIL PROTECTED]
WebMaster Universo Online - http://www.uol.com.br
Phone # +55 11 3038-8665


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] ORDER PROBLEMS

2001-05-15 Thread Rafael Faria

Hello Guys,

i'm with problems

first i try to add a value like "8.55" into my sql data base that was set 
up to DOUBLE (10,0) and isn't work... i don't know how this work... but i'm 
here to ask for someone explain me.

well... i did with varchar to add this value as i want to..

do i have a lot of values like


votes  average
   2 8.5
   10   5.5
   1 10
   205.1


and i wanna sort by votes and average

have someway to do that?


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] PHP] apostrophe's in PHP & MySQL

2002-01-08 Thread Rafael Perazzo

I have the same problem with the apostrophes in text
fields form object. When I try to enter a string that
contains ' the data is not entered in the database. I
use PHP 4 and Mysql 3.23. 
How can I avoid this problem ? 

__
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Apostrophes and text fileds forms

2002-01-08 Thread Rafael Perazzo

>You need to apply addSlashes() to the text fields
>before entering
>them into the database.

>Jason
What is an addSlash ? 
How can I appy addSlashes ? Can anyone give me an
example ? 

Thanks
Rafael Perazzo


__
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Development environment

2002-01-12 Thread Rafael Perazzo

I know two good IDEs for PHP: 
PhpEdit -> http://www.phpedit.com 
PhpCode -> http://www.phpide.de

Have fun!!

Rafael Perazzo


--- Morten Nielsen <[EMAIL PROTECTED]> wrote:
> Hi,
> 
> Can anybody recommend a good development
> environment? It should support PHP,
> HTML and JavaScripts.
> Another question...Is it normal procedure to mix the
> above 3 languages on a
> single page or is it possible to only use 1...i.e
> PHP?
> 
> Regards,
> Morten



__
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Php.ini file missing

2002-01-13 Thread Rafael Perazzo

I think that you have this problem because your
sendmail is not running. 
Try to run your sendmail (probably this command
/etc/rc.d/init.d/./sendmail 
start- Note that before the name sendmail you have
two chars ./) 
and I think your problem will be fixed. Then test your
script again to see 
if it's working. 

If this do not work, write again, I'll be very happy
to help the php 
community. 

Rafael Perazzo


__
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Read a var from stdin

2002-05-18 Thread Rafael Perazzo

Is there any way to ask the user to type the value of
a variable from stdin ? (like read in Pascal, or scanf
in C). I'm using PHP from command line. 

Thanks 

Rafael Perazzo

__
Do You Yahoo!?
LAUNCH - Your Yahoo! Music Experience
http://launch.yahoo.com

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




Re: [PHP] creating MySQL Users

2002-03-29 Thread Rafael Perazzo

Try this query : 

   $query = "GRANT SELECT,INSERT,UPDATE,DELETE,ALTER
";
   $query .= "ON $username ";
   $query .= "TO $username@localhost ";
   $query .= "IDENTIFIED BY '$password';";

Make sure that you put a blank space after each
string, except the last one. 
I hope this work!

Rafael Perazzo 

--- Liam <[EMAIL PROTECTED]> wrote:
> 29/03/2002 10:26:41 PM
> 
> Hi, I've been trying to work this out, but I can't.
> Myabe I need more sleep, I'm sure it's something
> really stupid.
> 
> Could someone have a look over this code for me
> please?
> It's meant to add MySQL users.
> 
> 
> ">
> User
> Password
> 
> 
> 
>  if ($REQUEST_METHOD=="POST") { 
> 
>   $mysql_access = mysql_connect("localhost", "root",
> "password");
>   if (!$mysql_access) { echo("ERROR: " .
> mysql_error() . "\n"); }
>   $query = "GRANT SELECT,INSERT,UPDATE,DELETE,ALTER";
>   $query .= "ON $username";
>   $query .= "TO $username@localhost";
>   $query .= "IDENTIFIED BY '$password';";
>   mysql_query($query, $mysql_access);
> 
>   print("Successfully added $username to the MySQL
> database!");
> 
> } 
> ?>
> 
> 
> Thanks,
> Liam
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


__
Do You Yahoo!?
Yahoo! Greetings - send holiday greetings for Easter, Passover
http://greetings.yahoo.com/

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




[PHP] Error: 1 is not a valid mysql link resource

2001-10-24 Thread Rafael Steil


Hi all.  
With php version 4.0.1, I made a database class. I use a function called 
connect() to open database connection to mysql, and the link resource is 
stored in $GLOBALS["CONNETION_ID"] global variable. All of code work 
perfectly, with no any problems..
But when I upgraded to php version 4.0.6, the code wasn't work at all. The 
error returned is 

Warning: 1 is not a valid MySQL-Link resource in 
/usr/local/apache/htdocs/Produtora/manole/config/site/database.class.php on 
line 190

the line 190, in this case, is just

$data = mysql_query($sql, $GLOBALS["CONNECTION_ID"])

it is the same code that works with php 4.0.1,,  The link resource is valid ( 
at least I think that ), because when I do

 echo $GLOBALS["CONNECTION_ID"];

the return is

Resource id #1

does anyone knows the problem???

thanks anyway,
Rafael Steil

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] file system question

2001-10-24 Thread Rafael Steil


Well, this is a problem.. with perl, you can use suidperl, but not with 
php.. the most easyest way is to give write permission to apache user to the 
directory you want to upload the files...

Rafael Steil

On Wednesday 24 October 2001 11:43, you wrote:
> Hello-
>
> I'm trying to write a php script that creates a directory and then copies
> uploaded files to that directory.  That isn't hard but what is hard is the
> fact that the script tells me that i do not have permission to do any of
> these actions.  I'm running red hat 7.1 and I have heard things about
> SetUID and sticky bits, however since I'm pretty much still a novice at
> linux I'm not too sure what to do.  The script is running under the
> username Apache any ideas?
>
> thanks..
> jay

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] CORRECT sort

2001-06-24 Thread Rafael Faria



I have a list of nicknames inside my page


  $t®ike_19a
  M@x<
  ARNALDO_MOTA20
  AXL-FUCKIN-ROSE
  AbAgUaLaDo
  Adolf
  Al_Cap0ne
  Anda_pelas_Sombr
  Anjo Tora
  Anjo_noturno
  Arcanjo_
  Atras_E_AVANTE
  BHILL
  BRAIN_DAMAGE
  BURNER
  B_l_a_d_e
  BaRTHY
  BichoPapaun
  BoNo-VoX
  Bob_Marley^
  Bony_Gyn
  Boy_in_Flames
  Buzz_Buzzard
  C@sþË®
  CA0S
  CARIOCA_H_19
  CLAUDIM
  CONVERTIDO
  COWBOY-DAS-MULHE
  Calu
  Cereau_Quiler
  Chrono_Jadson
  CoRTeZ
  Crash'n_Over
  Crison
  Cyberflux
  DIEGO (USA)
  DOOTman
  DhIMEnOr_
  DicK_DaLe
  Dick-||-Tracy
  Doc_Holiday
  DoomMan
  Duende_Fumacinha
  Dunkel
  EDDIE_|_VEDDER
  E_o_ToRa
  Ed_Cav@lerA
  Eslander
  Eudd
  F103_Mirage
  F14-TONCAT
  FREDDY2002
  FUNtastic
  FaIm
  Ferds
  Feyhong
  Feyhong
  Filipe_TJF
  FireBelt
  FlAnIgAnS
  FoRgAdOsEmKoNtIa
  Folley
  Fred_TJB
  Fulias
  GARTHBRooKs
  Gagary
  Gaspper_Man
  Gatinho Carente
  Geburah
  GiNeS_fRoBoW
  Godsmack
  GuiLhErMe_LP_17
  GustavoBond
  HADSPACE
  Hass
  HeItOrZiM
  HenRiQuE-GO
  IIGuttoII
  Ice_Hot
  IrOn_MaN-
  Ispirokado
  JONNY-BH
  JR2000
  Japa_loiro
  Jerry_Cantrell
  JuNiOr-GyN
  JuNiOr-JR
  Junior_GO
  KINDAROW
  Karaiba
  Khazed
  Kobaiat
  Krug
  LEO
  LOOSEBOY_DF
  Larry_Mullen_Jnr
  Leonardo-_-
  Lethal_Dan
  Liquidsnake
  LoS-LoCoS
  LoUkEtS
  Logansan
  Lone_Eagle
  Luisinho
  Lunnatic
  MAGNATO
  MAL-ACABADO
  MARCIOPAULISTANO
  aInFrAmE
  MaKoRn
  MaZiN
  Mackau
  McFlay
  McJay
  MoLeQuE_fEiO
  Monitorr
  Morte_aos_hansoN
  Mula_Cobain
  MuricocaTheCrazy
  Mwell
  MysteriousBoy
  NETO23A.
  Nash_Bridges
  NiCk_man
  Nivercon_JP_
  NoBIOS
  O-SuRtO
  OVERMARZ
  Orfheu
  Orion-br
  OsManoW_
  PDIOGO
  PISCAO
  PaSSoKKa
  Packardd-Pillow
  PcWizarD
  Pedro-A
  iQUi
  PiRaTaH
  Pumbassauro
  R@uL_GuNNe
  REILLER
  RICKY
  RPD
  Rave
  Red_Squadrow
  Rhumba
  Rideitor
  Ritler
  Rockslife
  SER_FEIO_DOI
  SIGFRIED
  SPOKEN
  Santana^
  ScoobyDubyDoo
  Seinfeld-
  Sheep_Man
  Sheepboy
  SiDMont
  Simple_Of_Heart
  Sir_Galahad
  Skolgt
  Sky_Cobain
  SpAnK_ThRu
  Spaik
  Spartacus_goiano
  Spider`s_Lullaby
  Spire_maze
  Stierman
  T-Blue_Wolf-T
  TC
  TIRAONDA_MAN_USA
  TOMPOO
  TYLLY
  Tabata-Jiraya
  Tekathlon
  The_Mad
  The_Scream
  ThiagoPozzato
  Tiglup
  Topera_Roedor
  Vegetal
  Victor
  Vox_Dei
  Wolwerine
  XXXReCrUtAXXX
  ZZOOOO
  [C410]
  [DarkWolf]
  [HellRayser]
  [SKELTER]
  [[[Amon-Ha]]]
  [mino]
  [{MORPHEU}]
  [{morpheu}]
  [|Dugy|]
  ^ANJO-DE-LUZ^
  ^AsTrOnOmY^
  ^Buiu^
  ^Poltergeist^
  ^Saga^
  ^SuBLinE^
  ^Tourniquet^
  ^MAU^^
  ^the-redpeppars^
  _Cheick_
  _Kaiser_
  _Magaiver_
  _ObsessioN_
  _PEnsADor_
  _]Speck[_
  _bandit_
  _marvin_
  _re_volt_VoX
  _xXJecaXx_
  antonelli
  bacteria_
  bad_clusters
  bitoca
  bowser
  bussund
  c_a_i_o
  cenourinha
  cessel
  chinforinforo
  colders
  cooldevil
  curquens
  derboy
  derboy
  didi_forever
  digb
  eygeryryrurt
  ezomatrixx
  ferdoido
  flakiko
  flyd
  free_e_o_mano
  gatodoido
  get46aps
  glauco-tavera
  haway_
  hebert
  jrhot-angel
  k@¥ßë®  ¤¤¤ anjo
  kadu-usa
  lindinho-usa
  llnetaoll
  m3rl1n
  mr-boy
  murilo_usa
  netao
  netscaper
  p3
  paul-USA
  pilha
  primo
  profvitor
  rafa_man
  rvt
  sLauGhter^
  scoop-mem
  silverfreak
  starvation
  trapizomba
  wolfthedie
  z3r0k
  {B_I_S_C_O_I_T_O
  {Blink-182}
  {Blink-182}
  {Prince}
  {ScReaM{
  {VeN0N_Br0WeR}
  {[DEDEL]}
  {[dust]}
  {]Kdinho[}
  {{AgAiNsT}}
  {{SPRINT}}
  {{WhiteWolf}}
  {{vbsk8}}
  {{{iron}}}
  }???
  {}CeLiM{}
  |AtEcUbAnOs|{
  |BaRdOk|
  |CirrOZZY|
  |JAMES-HETFIELD|
  |MaVeRiCk|
  |NiZoN|
  |PiRuLiTo|
  |RICKFIO|
  |RzO|
  |SuperMan|
  |TiBoR|
  |_DaNgErOuS_|
  |_ninguem_|
  |vasquito|
  ||AciD_PillS||
  ||Corinthiano||
  ||DeUsGrEgU||
  ||EmINeM||
  ||Guest||
  ||LoRd||
  ||Th0MaS_Br0wN||
  ||gusT

[PHP] installing error

2007-05-25 Thread Rafael Mora

Hello does anyone know the correct way to install PHP and APACHE (last
versions both of them) on WinXP???, Im doing it with the installers and I
cannot even run phpinfo(); script, I see apache's error log and it says that
i cant find SAM directory

Thank you in advance
Rafa


Re: [PHP] installing error

2007-05-26 Thread Rafael Mora

Thank you very much for you answers!!! =), but Im trying to work with
PostgreSQL.

So Im gonna review your suggestions in order to see which would be the best
for me

Thank you very much!

Rafa


On 5/26/07, Sathyashrayan <[EMAIL PROTECTED]> wrote:




On 5/26/07, Tijnema <[EMAIL PROTECTED]> wrote:
>
> On 5/26/07, Richard Davey <[EMAIL PROTECTED]> wrote:
> > Hi Rafael,
> >
> > Saturday, May 26, 2007, 12:38:15 AM, you wrote:
> >
> > > Hello does anyone know the correct way to install PHP and APACHE
> (last
> > > versions both of them) on WinXP???, Im doing it with the installers
> and I
> > > cannot even run phpinfo(); script, I see apache's error log and it
> says that
> > > i cant find SAM directory
> >
> > http://wamp.corephp.co.uk
> >
> > Cheers,
> >
> > Rich



May be this helps.

http://www.tanguay.info/wamp/installPhp5.php5



--
"War doesn't determine who is right, war determines who is left."
 Chinese
proverb


Re: [PHP] Re: installing error

2007-05-26 Thread Rafael Mora

thank you jared!, Im gonna try WAMPP!!, I hope this work, and a message for
php people: nice product but make it easy! lol

thank you
Rafa


On 5/26/07, Jared Farrish <[EMAIL PROTECTED]> wrote:


> Thank you very much for you answers!!! =), but Im trying to work with
> PostgreSQL.

I have never installed PostgreSQL, but I have installed Apache and PHP
together. Three suggestions:

1. Forget the installers. They are worthless, since all you're doing is
adding or editing a few config file lines, plus adding a PATH variable.
2. Where and how you change those files is important, though, so you need
to
google the version of php and apache you are installing and follow those
directions. It's tricky the first time, though. Be patient.
3. Start apache during your testing through a command-line. The error
reporting is much better on the command-line.

Also, really try not to put your PHP library in your System32 folder. This
is bad practice. Edit the PATH variable to point at where it should be
looking for the library.

> So Im gonna review your suggestions in order to see which would be the
best
> for me

WAMPP makes apache and php installation stupid easy (MySQL too, but you
don't seem to need it). Maybe, you might install WAMPP, uninstall MySQL,
and
install PostgreSQL... Never done it, but with some fiddling, it should
work.

--
Jared Farrish
Intermediate Web Developer
Denton, Tx

Abraham Maslow: "If the only tool you have is a hammer, you tend to see
every problem as a nail." $$



[PHP] send a file or stream

2006-08-29 Thread Rafael Mora

Hi!

i want to send a file or output stream in a .php, but first compress it, I
tryed the example to compress files but how do i do to send as answer to the
http request??

Rafa


Re: [PHP] replace single and double quotes

2006-08-29 Thread Rafael Mora

Hi!

i want to send a file or output stream in a .php, but first compress it, I
tryed the example to compress files but how do i do to send as answer to the
http request??

Rafa


[PHP] Test!

2006-08-29 Thread Rafael Mora

Hello! this is a test, can anyone tell me if u are getting my emails??

Thank you


Fwd: [PHP] send a file or stream

2006-08-29 Thread Rafael Mora

-- Forwarded message --
From: Rafael Mora <[EMAIL PROTECTED]>
Date: Aug 29, 2006 11:09 PM
Subject: Re: [PHP] send a file or stream
To: Peter Lauri <[EMAIL PROTECTED]>

1. A user sends a request to your server to get a compressed file
2. You compress the file on the server
3. I want to send back the file to the user




On 8/29/06, Peter Lauri <[EMAIL PROTECTED]> wrote:


Do you mean the following:

1. A user sends a request to your server to get a compressed file
2. You compress the file on the server
3. You want to send back to compressed file to the server

It is number 3 you asking for?

In that case:



/Peter


-Original Message-
From: Rafael Mora [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 30, 2006 2:34 AM
To: php-general@lists.php.net
Subject: [PHP] send a file or stream

Hi!

i want to send a file or output stream in a .php, but first compress it, I
tryed the example to compress files but how do i do to send as answer to
the
http request??

Rafa




Re: [PHP] send a file or stream

2006-08-29 Thread Rafael Mora

ok thank you Im going to test it!! =)

On 8/29/06, Peter Lauri <[EMAIL PROTECTED]> wrote:


  



Should do it then… if you know the path to the file :)


 --

*From:* Rafael Mora [mailto:[EMAIL PROTECTED]
*Sent:* Wednesday, August 30, 2006 10:10 AM
*To:* Peter Lauri
*Subject:* Re: [PHP] send a file or stream



1. A user sends a request to your server to get a compressed file
2. You compress the file on the server
3. I want to send back the file to the user







On 8/29/06, *Peter Lauri* <[EMAIL PROTECTED]> wrote:

Do you mean the following:

1. A user sends a request to your server to get a compressed file
2. You compress the file on the server
3. You want to send back to compressed file to the server

It is number 3 you asking for?

In that case:



/Peter


-Original Message-
From: Rafael Mora [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 30, 2006 2:34 AM
To: php-general@lists.php.net
Subject: [PHP] send a file or stream

Hi!

i want to send a file or output stream in a .php, but first compress it, I
tryed the example to compress files but how do i do to send as answer to
the
http request??

Rafa





Re: [PHP] send a file or stream

2006-08-29 Thread Rafael Mora

I test it and gave me this: xœ ÉÈ,V¢D…'Ôâ=(r)(??/§C0/¿D!1O!3·
¿¨$1¯D¡¸¤(3/] LÖ so the user should read that?? this is my code:


 6, 'window' => 15, 'memory' => 9);

$texto_original = "This is a test.\nThis is only a test.\nThis is not an
important string.\n";
//echo "El texto original tiene " . strlen($texto_original) . "
caracteres.\n";

$da = fopen('stations.gzip', 'w');
stream_filter_append($da, 'zlib.deflate', STREAM_FILTER_WRITE, $params);
fwrite($da, $texto_original);
fclose($da);

header("Content-Type: application/octet-stream");
readfile("stations.gzip");



On 8/29/06, Peter Lauri <[EMAIL PROTECTED]> wrote:






Should do it then. if you know the path to the file :)



_

From: Rafael Mora [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 30, 2006 10:10 AM
To: Peter Lauri
Subject: Re: [PHP] send a file or stream



1. A user sends a request to your server to get a compressed file
2. You compress the file on the server
3. I want to send back the file to the user







On 8/29/06, Peter Lauri <[EMAIL PROTECTED]> wrote:

Do you mean the following:

1. A user sends a request to your server to get a compressed file
2. You compress the file on the server
3. You want to send back to compressed file to the server

It is number 3 you asking for?

In that case:



/Peter


-Original Message-
From: Rafael Mora [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 30, 2006 2:34 AM
To: php-general@lists.php.net
Subject: [PHP] send a file or stream

Hi!

i want to send a file or output stream in a .php, but first compress it, I
tryed the example to compress files but how do i do to send as answer to
the

http request??

Rafa







Re: [PHP] send a file or stream

2006-08-29 Thread Rafael Mora

Ok it works, but it returns me the same .php file, not the one I am creating



On 8/29/06, Peter Lauri <[EMAIL PROTECTED]> wrote:


You need to make sure that you are not outputting ANYTHING before you do
this. I might guess that you have a whitespace in the top of the script. As
soon as you output, the server can not send any more header information, and
the browser will think it is just text instead of treating it as an
octet-stream.



/Peter



_

From: Rafael Mora [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 30, 2006 10:25 AM
To: Peter Lauri
Cc: php-general@lists.php.net
Subject: Re: [PHP] send a file or stream



I test it and gave me this: xœ ÉÈ,V¢D…'Ôâ=(r)(??/§C0/¿D!1O!3·
¿¨$1¯D¡¸¤(3/] LÖ‑ so the user should read that?? this is my code:



 6, 'window' => 15, 'memory' => 9);

$texto_original = "This is a test.\nThis is only a test.\nThis is not an
important string.\n";
//echo "El texto original tiene " . strlen($texto_original) . "
caracteres.\n";

$da = fopen('stations.gzip', 'w');
stream_filter_append($da, 'zlib.deflate', STREAM_FILTER_WRITE, $params);
fwrite($da, $texto_original);
fclose($da);

header("Content-Type: application/octet-stream");
readfile("stations.gzip");





On 8/29/06, Peter Lauri <[EMAIL PROTECTED]> wrote:





Should do it then. if you know the path to the file :)



_

From: Rafael Mora [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 30, 2006 10:10 AM
To: Peter Lauri
Subject: Re: [PHP] send a file or stream



1. A user sends a request to your server to get a compressed file
2. You compress the file on the server
3. I want to send back the file to the user







On 8/29/06, Peter Lauri <[EMAIL PROTECTED]> wrote:

Do you mean the following:

1. A user sends a request to your server to get a compressed file
2. You compress the file on the server
3. You want to send back to compressed file to the server

It is number 3 you asking for?

In that case:



/Peter


-Original Message-
From: Rafael Mora [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 30, 2006 2:34 AM
To: php-general@lists.php.net
Subject: [PHP] send a file or stream

Hi!

i want to send a file or output stream in a .php, but first compress it, I
tryed the example to compress files but how do i do to send as answer to
the

http request??

Rafa











Re: [PHP] send a file or stream

2006-08-30 Thread Rafael Mora

Hi!!

Well it works now, but with another issue, when I download it, it says that
it size is 0 bytes!!

i fwrite the file in a while, is it correct?

header()...
while()
{
 fwrite($da, "$somevar1:$somevar2");
}
fclose($da);

readfile();

thanks



On 8/30/06, Peter Lauri <[EMAIL PROTECTED]> wrote:


Try this:

header("Pragma: public");
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/octet-stream");
header('Content-Disposition: attachment; filename="stations.gzip"');
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize(stations.gzip));
readfile("stations.gzip");

/Peter

PS! To maintain the list and its functionality, do not post same message
multiple times  DS!


-Original Message-
From: Rafael Mora [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 30, 2006 11:01 AM
To: Peter Lauri
Cc: php-general@lists.php.net
Subject: Re: [PHP] send a file or stream

Ok it works, but it returns me the same .php file, not the one I am
creating



On 8/29/06, Peter Lauri <[EMAIL PROTECTED]> wrote:
>
> You need to make sure that you are not outputting ANYTHING before you do
> this. I might guess that you have a whitespace in the top of the script.
As
> soon as you output, the server can not send any more header information,
and
> the browser will think it is just text instead of treating it as an
> octet-stream.
>
>
>
> /Peter
>
>
>
> _
>
> From: Rafael Mora [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, August 30, 2006 10:25 AM
> To: Peter Lauri
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] send a file or stream
>
>
>
> I test it and gave me this: xœ ÉÈ,V¢D…'Ôâ=(r)(??/§C0/¿D!1O!3·
> ¿¨$1¯D¡¸¤(3/] LÖ‑ so the user should read that?? this is my code:
>
>
>
>  $params = array('level' => 6, 'window' => 15, 'memory' => 9);
>
> $texto_original = "This is a test.\nThis is only a test.\nThis is not an
> important string.\n";
> //echo "El texto original tiene " . strlen($texto_original) . "
> caracteres.\n";
>
> $da = fopen('stations.gzip', 'w');
> stream_filter_append($da, 'zlib.deflate', STREAM_FILTER_WRITE, $params);
> fwrite($da, $texto_original);
> fclose($da);
>
> header("Content-Type: application/octet-stream");
> readfile("stations.gzip");
>
>
>
>
>
> On 8/29/06, Peter Lauri <[EMAIL PROTECTED]> wrote:
>
>  header("Content-Type: application/octet-stream");
> readfile("path_to_compressed_file");
> ?>
>
>
>
> Should do it then. if you know the path to the file :)
>
>
>
> _
>
> From: Rafael Mora [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, August 30, 2006 10:10 AM
> To: Peter Lauri
> Subject: Re: [PHP] send a file or stream
>
>
>
> 1. A user sends a request to your server to get a compressed file
> 2. You compress the file on the server
> 3. I want to send back the file to the user
>
>
>
>
>
>
>
> On 8/29/06, Peter Lauri <[EMAIL PROTECTED]> wrote:
>
> Do you mean the following:
>
> 1. A user sends a request to your server to get a compressed file
> 2. You compress the file on the server
> 3. You want to send back to compressed file to the server
>
> It is number 3 you asking for?
>
> In that case:
>
>  header("Content-Type: application/octet-stream");
> readfile("path_to_compressed_file");
> ?>
>
> /Peter
>
>
> -Original Message-
> From: Rafael Mora [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, August 30, 2006 2:34 AM
> To: php-general@lists.php.net
> Subject: [PHP] send a file or stream
>
> Hi!
>
> i want to send a file or output stream in a .php, but first compress it,
I
> tryed the example to compress files but how do i do to send as answer to
> the
>
> http request??
>
> Rafa
>
>
>
>
>
>
>
>
>

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




Re: [PHP] Query result column to array

2006-08-30 Thread Rafael Mora

Hi!!

What I do is just this:

$_ar = array();


  while($_field = mysql_fetch_row($_result))
  {$_aloft["$_field[0]"] = "$_field[1]";}

  while(list($_key,$_val) = each($_ar))


On 8/30/06, Christopher Watson <[EMAIL PROTECTED]> wrote:


I'm looking for a native method for taking all of the values from one
column of a query result and creating an array of those values.
Procedurally, I'd tend to want to do this:

query("SELECT my_id FROM my_table");
while ($row = $query_result->fetchRow())
   $my_id_array[] = $row['my_id'];
?>

Heck, ColdFusion has the ValueList function which does exactly what I
want (of course, it returns a delimited list [string], not a native
array, but the one-step method is there).  Is there anything in
PHP-land that does that?  Or am I pretty much stuck using some
variation of the code above?

Christopher Watson
Principal Architect
The International Variable Star Index (VSX)
http://vsx.aavso.org

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




Re: [PHP] send a file or stream

2006-08-30 Thread Rafael Mora

I can download it, but when I see the file I downloaded has 0 bytes, and I
have readfile("stations.zip");




On 8/30/06, Peter Lauri <[EMAIL PROTECTED]> wrote:


But can you download it correctly? Is it just the download box that shows
0 bytes?

Or is it so that you actually is doing what you do below readfile()
without any argument? So that you are actually downloading something empty?
:)

/Peter



-Original Message-----
From: Rafael Mora [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 30, 2006 8:00 PM
To: php-general@lists.php.net
Subject: Re: [PHP] send a file or stream

Hi!!

Well it works now, but with another issue, when I download it, it says
that
it size is 0 bytes!!

i fwrite the file in a while, is it correct?

header()...
while()
{
fwrite($da, "$somevar1:$somevar2");
}
fclose($da);

readfile();

thanks



On 8/30/06, Peter Lauri <[EMAIL PROTECTED]> wrote:
>
> Try this:
>
> header("Pragma: public");
> header("Expires: 0"); // set expiration time
> header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
> header("Content-Type: application/octet-stream");
> header('Content-Disposition: attachment; filename="stations.gzip"');
> header("Content-Transfer-Encoding: binary");
> header("Content-Length: ".filesize(stations.gzip));
> readfile("stations.gzip");
>
> /Peter
>
> PS! To maintain the list and its functionality, do not post same message
> multiple times  DS!
>
>
> -Original Message-
> From: Rafael Mora [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, August 30, 2006 11:01 AM
> To: Peter Lauri
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] send a file or stream
>
> Ok it works, but it returns me the same .php file, not the one I am
> creating
>
>
>
> On 8/29/06, Peter Lauri <[EMAIL PROTECTED]> wrote:
> >
> > You need to make sure that you are not outputting ANYTHING before you
do
> > this. I might guess that you have a whitespace in the top of the
script.
> As
> > soon as you output, the server can not send any more header
information,
> and
> > the browser will think it is just text instead of treating it as an
> > octet-stream.
> >
> >
> >
> > /Peter
> >
> >
> >
> > _
> >
> > From: Rafael Mora [mailto:[EMAIL PROTECTED]
> > Sent: Wednesday, August 30, 2006 10:25 AM
> > To: Peter Lauri
> > Cc: php-general@lists.php.net
> > Subject: Re: [PHP] send a file or stream
> >
> >
> >
> > I test it and gave me this: xœ ÉÈ,V¢D…'Ôâ=(r)(??/§C0/¿D!1O!3·
> > ¿¨$1¯D¡¸¤(3/] LÖ‑ so the user should read that?? this is my code:
> >
> >
> >
> >  > $params = array('level' => 6, 'window' => 15, 'memory' => 9);
> >
> > $texto_original = "This is a test.\nThis is only a test.\nThis is not
an
> > important string.\n";
> > //echo "El texto original tiene " . strlen($texto_original) . "
> > caracteres.\n";
> >
> > $da = fopen('stations.gzip', 'w');
> > stream_filter_append($da, 'zlib.deflate', STREAM_FILTER_WRITE,
$params);
> > fwrite($da, $texto_original);
> > fclose($da);
> >
> > header("Content-Type: application/octet-stream");
> > readfile("stations.gzip");
> >
> >
> >
> >
> >
> > On 8/29/06, Peter Lauri <[EMAIL PROTECTED]> wrote:
> >
> >  > header("Content-Type: application/octet-stream");
> > readfile("path_to_compressed_file");
> > ?>
> >
> >
> >
> > Should do it then. if you know the path to the file :)
> >
> >
> >
> > _
> >
> > From: Rafael Mora [mailto:[EMAIL PROTECTED]
> > Sent: Wednesday, August 30, 2006 10:10 AM
> > To: Peter Lauri
> > Subject: Re: [PHP] send a file or stream
> >
> >
> >
> > 1. A user sends a request to your server to get a compressed file
> > 2. You compress the file on the server
> > 3. I want to send back the file to the user
> >
> >
> >
> >
> >
> >
> >
> > On 8/29/06, Peter Lauri <[EMAIL PROTECTED]> wrote:
> >
> > Do you mean the following:
> >
> > 1. A user sends a request to your server to get a compressed file
> > 2. You compress the file on the server
> > 3. You want to send back to compressed file to the server
> >
> > It is number 3 you asking for?
> >
> > In that case:
> >
> >  > header("Content-Type: application/octet-stream");
> > readfile("path_to_compressed_file");
> > ?>
> >
> > /Peter
> >
> >
> > -Original Message-
> > From: Rafael Mora [mailto:[EMAIL PROTECTED]
> > Sent: Wednesday, August 30, 2006 2:34 AM
> > To: php-general@lists.php.net
> > Subject: [PHP] send a file or stream
> >
> > Hi!
> >
> > i want to send a file or output stream in a .php, but first compress
it,
> I
> > tryed the example to compress files but how do i do to send as answer
to
> > the
> >
> > http request??
> >
> > Rafa
> >
> >
> >
> >
> >
> >
> >
> >
> >
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>




Re: [PHP] send a file or stream

2006-08-31 Thread Rafael Mora

Thank you very much Curt!, I'm tests right now with this. The client is not
a web browser, it is an application that calls the .php file with $_GET
params, and the app waits to receive the file compressed, this is the way I
want it to work!

I'll let u know about this. But anyway thank you

Rafa

PS: what is that ob_start though?


On 8/31/06, Curt Zirzow <[EMAIL PROTECTED]> wrote:


On 8/29/06, Rafael Mora <[EMAIL PROTECTED]> wrote:
> Hi!
>
> i want to send a file or output stream in a .php, but first compress it,
I
> tryed the example to compress files but how do i do to send as answer to
the
> http request??

Unlike my recent posts, this could be a candidate for using ob_*

There is no need to compress it first, just use ob_start('ob_gzhandler');

if the client supports a compression method, no special things are
needed and the content sent is compressed otherwise it is sent without
compression.

see http://php.net/ob-gzhandler for more info.

HTH,
Curt.

Curt.



Re: [PHP] Error Handling Library?

2006-08-31 Thread Rafael Mora

Hi!, u can extend the exception class and handle ur own errors, If u need
help let me know!

Rafa


On 8/31/06, Jay Paulson <[EMAIL PROTECTED]> wrote:


I've been doing some research and was wondering if anyone out there has
written a library for error handling?  I haven't found anything as of yet
but would love to hear suggestions!

Thanks!

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




Re: [PHP] How do I call an class?

2006-09-08 Thread Rafael Mora

Hi!

I think u are confused, the variable name doesnt have anything to do with
the Class name...


So you can have something like this:

$myvar = new shuttle();
$jjj = new ISS();

u just need to be sure that u are using the exact name of the class, it
doesnt matter the variable name,

hope u get clear!

bye, from Venezuela
Rafa


On 9/8/06, Sr. Paulo Ricardo <[EMAIL PROTECTED]> wrote:


Good morning.





How do I call an class?





It's correct?



$Class  = new Class();



or



$class = new Class();





Att,

'É um orgulho ter você como nosso cliente'


Paulo Ricardo
Programador (Desenvolvedor)

ArgoHost.net
Hospedagem Web com Facilidade
 http://www.argohost.net
Suporte Telefônico: (85) 3264-9944 / (11) 4063-4844
E-mail:   [EMAIL PROTECTED]







Re: [PHP] How to effectuate translations

2006-09-29 Thread Rafael Mora

Hi!, well u can write ur messages in differents files, and like a make a
class where u can put a method like getMessage($_type), this class could
contains the language already selected, and just load the messages for that
language in a "array"(or another easy to use PHP data structure).

What do you think??

I know nothing about this, but I hope this help u

Rafa


On 9/29/06, AR <[EMAIL PROTECTED]> wrote:


Hi,

I'm coding this software that has several files for several languages,
so that users can chose the one that suits him.

My question is what is the best way to integrate this in the PHP code,
i. e., to make it work.

Any help would be appreciated.

Warm regards,
Augusto Reis

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




[PHP] Re: An extension to CREATE zips??

2004-03-15 Thread Rafael Cotta
I already made something like this on Linux using the exec function and zip
command. You'll need to find a command line zip utility for Windows.

But be very careful on using data sent by the user for exec'ing.

Regards,

Rafael
http://cifradasweb.net/


"Brian J. Celenza" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Is there function library capable of creating zip files and adding files
to
> a zip archive under the windows/apache platform? After some extensive
> browsing I can only turn up read-only access functions.
>
> Thank you,
> Brian

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



  1   2   >