[PHP] Regex help

2005-06-06 Thread RaTT
Hi Guys, 

I am currently creating a once off text parser for a rather large
document that i need to strip out bits of information on certain
lines.

The line looks something like :


Adress line here, postcode, country Tel: +27 112233665 Fax: 221145221
Website: http://www.urlhere.com E-Mail: [EMAIL PROTECTED] TAGINCAPS: CAPS
RESPONSE Tag2: blah


I need to retreive the text after each marker i.e Tel: Fax: E-Email:
TAGINCAPS: ...

I have the following regex /Tel:\s*(.[^A-z:]+)/ and
/Fax:\s*(.[^A-z:]+)/ all these work as expected and stop just before
the next Tag. However I run into hassels  around the TAGINCAPS as the
response after it is all in caps and i cant get the Regex to stop just
before the next tag: which may be either all caps or lowercase.

I cant seem to find the regex that will retreive all chartures just
before a word with a :  regalrdless of case.

I have played around with the regex coach but still seem to be comming
up short so i thought i would see if anybody can see anything i might
have missed.

any help most appreciated. 

Regards 
Jarratt

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



[PHP] Dynamically loading function arguments

2005-05-31 Thread RaTT
Hi 

Currently we are building a basic content management system where we
would like to be able to write as libral customized tags as possible,

for example  [[select:array_name,title]] or [[form:name]] in the
format of [[function:arguments]]

The problem that we are experiencing are that the arguments are being
parsed as a single string, does anybody know of what function / method
i can use to get around this? My default option is to write the
functions to split the single supplied argument into their respective
arguments, but i am sure there is a easier way around?

I have tried splitting them up, and rejoining them with a , but i
think i am just redoing what php does internally.

Here is my current code,
?php

// function = select, array = _title_,  name= select_title

$str = {{select:_title_,select_title}};  

parse($str);

function parse($str){
$reg_ex  = '/\{\{([a-zA-Z0-9\-_]+):(.*)\}\}/';   //
{{function_name:paramaters,seperate,by,comma}}
preg_match_all($reg_ex,$str,$matches,PREG_SET_ORDER);
// $matches[0] = whole function 
// $matches[1] = function
// $matches[2] = content / params

   echo $match_count = count($matches);
for ($i=0;$i$match_count;$i++){
$output = null;
if(function_exists($matches[$i][1])){
//function has been declared 
// TO-DO: add safe mode function array to specify 
allowed functions
#echo  DEBUG: 
{$matches[$i][1]} ( {$matches[$i][2]} ) br
/\n;
$args = explode(,,$matches[$i][2]);
$cnt = count($args);
$params = null;
for($j=0; $j  $cnt; $j++){
#$params .= \$args[$j];
$params .= $args[$j];
$params .= ($j != ($cnt-1))? ,: ;
}// end for 
//eval(echo $params;);
//$output =
$matches[$i][1](implode(,,$args));//single str
   $output = $matches[$i][1]($params);
   $str = 
eregi_replace($matches[$i][0],$output,$str);
   } //end if 
   else {
// function not found or allowed remove tags
//echo DEBUG: function not foundbr /\n;
$str = eregi_replace($matches[$i][0],'',$str);
   }// end else 
}//end for
  return $str;  
  }
  
  function select($array='',$name='',$extra=''){
echo 'pre';
print_r(func_get_args());
echo '/pre';
  }
?

Kind regards 
Jarratt

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



Re: [PHP] Dynamically loading function arguments

2005-05-31 Thread RaTT
Hi Guys 

Thanks for your support, i will post the function once done. 

Regards 
Jarratt

On 5/31/05, Jochem Maas [EMAIL PROTECTED] wrote:
 RaTT wrote:
  Hi
 
  Currently we are building a basic content management system where we
  would like to be able to write as libral customized tags as possible,
 
  for example  [[select:array_name,title]] or [[form:name]] in the
  format of [[function:arguments]]
 
  The problem that we are experiencing are that the arguments are being
  parsed as a single string, does anybody know of what function / method
  i can use to get around this? My default option is to write the
  functions to split the single supplied argument into their respective
  arguments, but i am sure there is a easier way around?
 
  I have tried splitting them up, and rejoining them with a , but i
  think i am just redoing what php does internally.
 
 some funcs that might help you:
 
 compact()
 extract()
 call_user_func()
 call_user_func_array()
 
 also I recommend doing everything you can not to have to use
 an eval() statement anywhere with this code as that would be comparatively
 slow and you have to start worrying about possible security issues...
 
 lastly my personal preference is towards the preg_*() funcs
 rather than the eregi_*() funcs. regardless you should minimize the use
 of regular expressions if you can... use explode(), strstr() and the like
 where ever possible.
 
 if you find a neat way of making use of call_user_func_array() then I think
 you can cut the step where you rebuild the params string with commas.
 
 also you might want to check out the way the Smarty guys implemented their
 plugin/tag functionality - you may not like their style or implementation
 but no doubt there is some overlap in what you are trying to do and what
 they have done - so it may give you some ideas.
 
 good luck.
 
 
  Here is my current code,
  ?php
 
  // function = select, array = _title_,  name= select_title
 
  $str = {{select:_title_,select_title}};
 
  parse($str);
 
  function parse($str){
  $reg_ex  = '/\{\{([a-zA-Z0-9\-_]+):(.*)\}\}/';   //
  {{function_name:paramaters,seperate,by,comma}}
  preg_match_all($reg_ex,$str,$matches,PREG_SET_ORDER);
  // $matches[0] = whole function
  // $matches[1] = function
  // $matches[2] = content / params
 
 echo $match_count = count($matches);
  for ($i=0;$i$match_count;$i++){
  $output = null;
  if(function_exists($matches[$i][1])){
  //function has been declared
// TO-DO: add safe mode function array to specify 
  allowed functions
#echo  DEBUG: 
  {$matches[$i][1]} ( {$matches[$i][2]} ) br
  /\n;
$args = explode(,,$matches[$i][2]);
$cnt = count($args);
$params = null;
for($j=0; $j  $cnt; $j++){
#$params .= \$args[$j];
$params .= $args[$j];
$params .= ($j != ($cnt-1))? ,: ;
}// end for
//eval(echo $params;);
  //$output =
  $matches[$i][1](implode(,,$args));//single str
   $output = $matches[$i][1]($params);
   $str = 
  eregi_replace($matches[$i][0],$output,$str);
   } //end if
 else {
// function not found or allowed remove tags
//echo DEBUG: function not foundbr /\n;
$str = eregi_replace($matches[$i][0],'',$str);
 }// end else
  }//end for
return $str;
}
 
function select($array='',$name='',$extra=''){
echo 'pre';
print_r(func_get_args());
echo '/pre';
}
  ?
 
  Kind regards
  Jarratt
 
 


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



Re: [PHP] Highlighting a stored value as 'selected'

2005-02-08 Thread RaTT
Hello Alp 

Try something like, 

?php

//DB fields as an array   

$db_fields = array('left'= 'left', 
   'center'   = 'center', 
   'right'  = 'right');

function drop($array,$sel_name='',$sel_field='',$css=''){
$dropdown = select name=\$sel_name\ $css\n;
foreach($arr as $key = $val){
$sel = ($sel_field == $key)?' selected=selected':'';
$dropdown .= \t.'option 
value='.$key.''.$sel.''.$val.'/option'.\n;
}
$dropdown .= /select\n;
return $dropdown;
}
usage: 
echo drop($db_fields,'test_select','center');
?

HTH 
Jarratt



On Tue, 8 Feb 2005 17:14:24 +0800, Alp [EMAIL PROTECTED] wrote:
 Is there an easier way to display/highlight the value stored in the database
 for a select option? Such as:
 Stored value is 'center'. The statement is:
 print 'select name=colalign';
 print 'option value=leftLeft';
 print 'option value=centerCenter';
 print 'option value=rightRight';
 print '/select';
 
 I can have 3 sets of the above tied to 'if's but would rather ask for an
 easier or better way.
 
 Thanks in advance.
 
 Alp
 
 --
 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



Re: [PHP] How to prevent user directly input SQL query

2005-02-07 Thread RaTT
Hello Thone

you can use mysql_real_escape_string() or mysql_real_escape_string()
for versions prior to 4.3.0,  to aissist with quoting mysql queries,
if you use another DB, look at the manual for the relevant escape
function.

I use this function after just before i insert variables into a sql string.

function clean($var){
if(!get_magic_quotes_gpc()){
if(!function_exists(mysql_real_escape_string)){
return  mysql_escape_string($var);
}
return  mysql_real_escape_string($var);
}
if(!function_exists(mysql_real_escape_string)){
return  mysql_escape_string( stripslashes( $var));
}
return  mysql_real_escape_string( stripslashes( $var));
}

Then when details are submitted, make sure you clean any unwanted
content from those variables , also make sure input is what your
expecting,

i.e  if(ctype_digit($_GET['someid'])){
$cleanid = clean($_GET['someid']);
  }

$sql = SELECT `field` FROM `table` WHERE `someid`='$cleanid'; 

Also see http://phpsec.org/ its a new website that will help you on
your way to assisting with securing your php applications.

HTH 
Jarrattt 

On Mon, 07 Feb 2005 20:01:43 +0700, Thone [EMAIL PROTECTED] wrote:
 I'm curious about how to protect SQL query. For example, if I get some
 varaibles from user using GET or POST method. Then, I have to use it in
 a SQL query sentense. How can I make sure that users don't do trick by
 inserting some SQL command into the variable resulting in miss sql
 command? Is there any method to prevent that?
 
 Another question is that, are there any PHP build-in function to remove
 some unwanted charactor (like  and ' and \ and /  ...) or I have to do
 it manually?
 
 Best Regards,
 Thone
 
 --
 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



Re: [PHP] cal_days_in_month() missing, how can I tell if it exists

2005-02-01 Thread RaTT
Hi James, 

http://uk.php.net/manual/en/function.function-exists.php, should help
you on your way.

hth 
Jarratt


On Tue, 1 Feb 2005 18:57:12 -0600, James Kaufman
[EMAIL PROTECTED] wrote:
 On Tue, Feb 01, 2005 at 08:47:29PM +, Ben Edwards wrote:
  I have been implementing a system on a different ISP than I normally use
  and have got:-
 
  Fatal error: Call to undefined function: cal_days_in_month()
  in 
  /home/hosted/www.menublackboard.com/public_html/dev/classes/validator.class.php
  on line 134
 
  I found a reference to this an the web and it seems PHP is not compiled
  with calender support.
 
  recompile php with the --enable-calendar option.
 
  Cant see being able to get the to re-compile PHP so I guess I am going
  to have to disable the feature.  I seem to remember a while ago seeing a
  function to test weather a function exists in PHP.  That way I can have
  the relevant validation skipped if the function is missing (I will tell
  the client if they get decent hosting it will start working).
 
  So something like
 
function_exists(  cal_days_in_month() )
 
  Anyone know what the function is called.
 
  Ben
 
 
 I do this:
 
 if (!extension_loaded('calendar'))
 {
 /*
  * cal_days_in_month($month, $year)
  * Returns the number of days in a given month and year,
  * taking into account leap years.
  *
  * $month: numeric month (integers 1-12)
  * $year: numeric year (any integer)
  *
  * Prec: $month is an integer between 1 and 12, inclusive
  *   $year is an integer.
  * Post: none
  */
 function cal_days_in_month($month, $year)
 {
 return $month == 2 ? $year % 4 ? 28 : 29 : ($month % 7 % 2 ? 31 : 30);
 }
 }
 
 --
 Jim Kaufman
 Linux Evangelist
 public key 0x6D802619, CISSP# 65668
 http://www.linuxforbusiness.net
 ---
 The shortest distance between two points is through Hell.
 --Brian Clark
 
 --
 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



Re: [PHP] Preg_match----------help

2005-01-22 Thread RaTT
Hello, 

This regular expresion should help you on your way 

$regex = /[A-z_\-]+?/;

HTH 
Jarratt

On Sat, 22 Jan 2005 17:03:30 +0600, Chandana Bandara
[EMAIL PROTECTED] wrote:
 hi ,
 
 using preg_match , how can i match , _ ,   -  such special 
 characters in a sentence  ???
 
 Eg:
 
 Strings are like this,
 
 1.Ahgrwgsgd dfjb yuhh dfh ABCD AFGHFDc GHJGKJ -- here i want 
 to match  ABCD
 
 2.AFRYRGH  vhGHJGB ASD_ASD_DER GHJGJ  kjHGKJGK -- here i want to 
 match  ASD_ASD_DER
 
 3.GHHTGH GHJK BO-CA JKJ JLKL ---here i want to match  BO-CA
 
 what is the most suitable way to match those data ? plz guide me ,
 
 Thanx in advance,
 chandana
 


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



Re: [PHP] Re: regular expression help

2005-01-21 Thread RaTT
Hi, 

From what i can see you dont even need to call global, as your passing
variables to the function ? this could be causing the script to
confuse itself.

hth


On Fri, 21 Jan 2005 09:30:21 -0700, Jason [EMAIL PROTECTED] wrote:
 Jason wrote:
  Simple functions to check  fix if necessary invalid formating of a MAC
  address... I seem to be having problems with the global variable $mac
  not being returned from the fix_mac() function.  Any help is appreciated.
 
  ?php
  /*
   * ex. 00:AA:11:BB:22:CC
   */
  function chk_mac( $mac ) {
  global $mac;
   if( eregi(
  ^[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}\:[0-9A-Fa-f]{2}$,
  $mac ) ) {
return 0;
   } else {
return 1;
   }
  }
 
  /*
   * check validity of MAC  do replacements if necessary
   */
  function fix_mac( $mac ) {
   global $mac;
   /* strip the dash  replace with a colon */
   if( eregi(
  ^[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}\-[0-9A-Fa-f]{2}$,
  $mac ) ) {
$mac = preg_replace( /\-/, :, $mac );
return $mac;
   }
   /* add a colon for every two characters */
   if( eregi( ^[0-9A-Fa-f]{12}$, $mac ) ) {
/* split up the MAC and assign new var names */
@list( $mac1, $mac2, $mac3, $mac4, $mac5, $mac6 ) = @str_split( $mac,
  2 );
/* put it back together with the required colons */
$mac = $mac1 . : . $mac2 . : . $mac3 . : . $mac4 . : . $mac5 .
  : . $mac6;
return $mac;
   }
  }
 
  // do our checks to make sure we are using these damn things right
  $mac1 = 00aa11bb22cc;
  $mac2 = 00-aa-11-bb-22-cc;
  $mac3 = 00:aa:11:bb:22:cc;
 
  // make sure it is global
  global $mac;
 
  // if mac submitted is invalid check  fix if necessary
  if( chk_mac( $mac1 ) != 0 ) {
   $mac = fix_mac( $mac1 ); echo $mac1 .  converted to  . $mac . br;
  }
  if( chk_mac( $mac2 ) != 0 ) {
   $mac = fix_mac( $mac2 ); echo $mac2 .  converted to  . $mac . br;
  }
  if( chk_mac( $mac3 ) != 0 ) {
   $mac = fix_mac( $mac3 ); echo $mac3 .  converted to  . $mac . br;
  }
 
  ?
 Still does not resolve the problem.  declaring $mac as global in the
 chk_mac() function.
 
 --
 Jason Gerfen
 Student Computing
 Marriott Library
 801.585.9810
 [EMAIL PROTECTED]
 
 And remember... If the ladies
   don't find you handsome, they
   should at least find you handy...
   ~The Red Green show
 
 --
 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



Re: [PHP] Calculate No Of Days

2005-01-03 Thread RaTT
Hi Khuram 

I use this function 

function daysLeft($startDate,$endDate=false){
// convert to timestamps

$start_stamp = strtotime($startDate);
$end_stamp   = ($endDate)?strtotime($endDate):time();

if($start_stamp  $end_stamp){
// start date is passed end date
return 0;
}
$difference = $end_stamp - $start_stamp;
return floor($difference/(24*60*60));
}

echo  daysleft(today, 01/05/2005);

Note, remeber to use the correct dat format otherwise you will see
some unexpected results.

Jarratt 


On Mon, 3 Jan 2005 02:33:58 -0800 (PST), khuram noman
[EMAIL PROTECTED] wrote:
 Hi
 
 Is there any function avialable in PHP to calculate
 the no of days by passing 2 dates like 1 argument is
 1/1/2005 and the second one is 1/2/2005 then it
 returns the no of days or how can i do that if there
 is no builtin function .
 
 Regards
 Khuram Noman
 
 __
 Do You Yahoo!?
 Tired of spam?  Yahoo! Mail has the best spam protection around
 http://mail.yahoo.com
 
 --
 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



Re: [PHP] Days remaining?

2004-12-03 Thread RaTT
Hi Peter, 

You can use this function 

function daysLeft($startDate,$endDate=false){
// convert to timestamps 
$start_stamp = strtotime($startDate);
$end_stamp   = ($endDate)?strtotime($endDate):time();
if($start_stamp  $end_stamp){
// start date is passed end date
return 0; 
}
$difference = $end_stamp - $start_stamp;
return floor($difference/(24*60*60));
}

echo daysLeft('2004-12-20','2004-12-25');


HTH 

Jarratt

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



Re: [PHP] How to implement mass emailing?

2004-10-07 Thread RaTT
Hi, 

you can create a mailscript to run seperartly in the background, so
when a administrator wishes to send a mass mail, it writes the content
to a database and then executes a stand alone mailing script eg:
exec(' php  phpmailscript.php  logflile.txt '); use the  to run the
script in the background.

This script can then pull info from a db (user and content) and mail
individually and log that the user was sent a email. This will also
save you the hassel of worring about administrators closing the
browser and having to resend the mail again and if there are thousands
of emails you can then schedual email's to be sent at specific times,
in the evening for example.

 HTH 
Jarratt


 


On Wed, 6 Oct 2004 22:58:59 -0700 (PDT), zareef ahmed [EMAIL PROTECTED] wrote:
 
 --- Tumurbaatar S. [EMAIL PROTECTED] wrote:
 
  The scenario is:
 
  1. Site administrator logs into his admin page and
  writes
  some message on a form.
  2. After clicking submit the web script should
  broadcast
  this message to several hundred subscribers.
 
 If you want to send the message as email mail() is the
 only option.
 
  And I'm wonder how to implement this on PHP.
  Sending an email to each subscribers can take
  a much time and PHP will stop after
  max_execution_time.
 you can set max time by  set_time_limit(), for disable
 time limit just use set_time_limit(0).
 
 BTW  register_shutdown_function() can be helpfull in
 handling performance related doubts.
 
 zareef ahmed
 
  Any ideas?
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 
 =
 Zareef Ahmed :: A PHP Developer in Delhi ( India ).
 Homepage :: http://www.zasaifi.com/zareef_ahmed.php
 
 
 ___
 Do you Yahoo!?
 Declare Yourself - Register online to vote today!
 http://vote.yahoo.com
 
 
 
 --
 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] Retrieving large results from a database ends in memory error.

2004-10-03 Thread RaTT
Hi Guys 

I am trying to retrieve over 5000 rows from a mysql database, i have
to use a SELECT * query as i am required to use all the fields for
display.

Everytime i try to run the code below i get a Allowed memory size of
10485760 bytes exhausted (tried to allocate 40 bytes). Now if i change
php's memory limit in the php.ini file to something like 80MB then its
fine, but i can't be guarantied that the person who this code is for
will be able or willing to access their php.ini file.

Basically what i am asking is there a better way to write this query
so i can still retrieve all the results from the database without
running into memory issues ? should i break it up into chunks and put
it through a loop ?

Any assitance on retriving large amout of info from a db would be most
appreciated.

THis is the basic code i am using: 

$q = SELECT * FROM `users` ORDER BY UserID;
$r = mysql_query($q) or die(There has been a query error: .mysql_error());
if($getR = mysql_fetch_array($r,MYSQL_ASSOC)){
   do {
   $userarray[] = $getR;
   }
   while($getR = mysql_fetch_array($r));
   echo 'Done retrieved '.count($getR).' records.';
}
else {
   echo 'there has been an error retrieving the results.';
}

Thanks 
Jarratt

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



Re: [PHP] Newbie array problem

2004-09-23 Thread RaTT
Hello 

Try this 
$array = array(1, 2, 3, 4, 5, 6, 7);
$display = implode(';',$array);
echo $display;

hth 
Jarratt

On Thu, 23 Sep 2004 13:16:03 +0300, Phpu [EMAIL PROTECTED] wrote:
 If i have an array
 $array = array(1, 2, 3, 4, 5, 6, 7)
 How can i display the array element sepparated by (;) like this
 $display = 1;2;3;4;5;6;7
 
 Thanks


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