[PHP] Re: rewrite urls with preg_replace

2002-11-28 Thread liljim
Hi Dieter,

You need to use the 'e' modifier as well as 'is' in your pattern. Have a
look in the manual, here:

http://www.php.net/manual/en/pcre.pattern.modifiers.php

"If this modifier is set, preg_replace() does normal substitution of
backreferences in the replacement string, evaluates it as PHP code, and uses
the result for replacing the search string."

Also look here:
http://www.php.net/manual/en/function.preg-replace.php

And check the "Example 2. Using /e modifier" part.

Hope that helps ;)

James


"Dieter Koch" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hi to all the PHP-Fans out there,
>
> i have a syntax-problem with the folowing preg_replace command:
>
> $returnString = preg_replace("/(href=\")(.+?)(\")/is",
> preg_quote("\\1".ebLinkEncode(."\\2".)."\\3"), $returnString);
>
> i'm trying to call my own function within a preg_replace function and it
> won't work.
> any ideas ? it seems to me, that the quoting is incorrect, but i'm not
> shure, why it is incorrect,
> especially because i use preg_quote() ...
>
> thanks in advance for some hints !
>
> best regards
> [EMAIL PROTECTED]
>
>
>
>
>



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




[PHP] Re: Check valid chars in string

2002-12-02 Thread liljim
It's missing a closing brace. I would, however, tend to drop that way of
doing things and use a regex:

function ValidChard($file_name)
{
if(preg_match("![^a-z0-9\-\.]!is", $file_name))
{
return false;
}
return true;
}

Much easier on the eye, don't you think? :)

James


"Magnus Nilsson" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
function valid_chars($file_name)
{

   for($i = 0; $i < strlen($file_name); $i++)
   {
if (!in_array($file_name[$i],
array('q','w','e','r','t','y','u','i','o','p','l','k','j','h',
'g','f','d','s','a','z','x','c','v','b','n','m','Q','W',
'E','R','T','Y','U','I','O','P','L','K','J','H','G','F',
'D','S','A','Z','X','C','V','B','N','M','0','1','2','3',
'4','5','6','7','8','9', '.', '_')))
  {
return false;
}
else
{
return true;
}
}

Found this snippet of code on php.net
(http://www.php.net/manual/sk/ref.strings.php), but it just reurns a
parse error.


OS: OS X 10.2
PHP: PHP 4.2.3
MYSQL: 3.23.51

// magnus n.





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




Re: [PHP] Struggling with code

2002-12-05 Thread liljim
Ben, consider re-working this slightly:

$result = mysql_query($sql,$connection) or mysql_error("Couldn't execute
query.");

mysql_error() doesn't take any arguments (other than maybe a resource
identifier ($connection, in this case)): it simply outputs problems, which
allows you to diagnose what's wrong with your script. Try throwing a bum
query in there and see what you get (I'm guessing it would be "not a valid
mysql resource on line 21/22", which you've already reported in another
e-mail).

This would be a better way of doing things:

$result = mysql_query($sql,$connection) or die("Query failure: " .
mysql_error());

-James


"Ben C." <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hugh, I took away the comma from $url and it works.
>
> Everyone, Thanks for your help!
>
> Ben
>
> -Original Message-
> From: Ben C. [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, December 05, 2002 12:15 AM
> To: [EMAIL PROTECTED]
> Subject: RE: [PHP] Struggling with code
>
>
> I have incorporated most of the suggestions.  My most recent code is:
>
> 
> $db_name = "db1";
> $table_name = "user";
>
> $connection = mysql_connect("localhost", "user", "password") or
> die("Couldn't connect.");
>
> $db = mysql_select_db($db_name, $connection) or die("Couldn't select
> database.");
>
> $sql = "UPDATE user
> SET
> name = '$name',
> lname = '$lname',
> mobil = '$mobil',
> email = '$email',
> url = '$url',
> WHERE id= '$id'
>
> ";
>
> $result = mysql_query($sql,$connection) or mysql_error("Couldn't execute
> query.");
>
>
> ?>
>
> -Original Message-
> From: Hugh Danaher [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, December 05, 2002 12:07 AM
> To: Ben C.
> Cc: [EMAIL PROTECTED]
> Subject: Re: [PHP] Struggling with code
>
>
> please post lines 20 and 21, get rid of all @, the comma after url='$url'
> and show your most recent code.  Others have posted and given you good
> advice, you should incorporate their suggestions.
>
> hugh
> - Original Message -
> From: "Ben C." <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Wednesday, December 04, 2002 11:44 PM
> Subject: RE: [PHP] Struggling with code
>
>
> > I am now getting the following error:
> >
> > Warning: Supplied argument is not a valid MySQL-Link resource in
> > /home/httpd/vhosts/localhost/httpdocs/data/up.php
> > on line 21
> >
> > Why do you think that is?
> >
> > -Original Message-
> > From: Jason Wong [mailto:[EMAIL PROTECTED]]
> > Sent: Wednesday, December 04, 2002 9:53 PM
> > To: [EMAIL PROTECTED]
> > Subject: Re: [PHP] Struggling with code
> >
> >
> > On Thursday 05 December 2002 13:24, Ben C. wrote:
> > > I am struggling with the code below.  I keep getting the error
"Couldn't
> > > execute query".  Please help me out, let me know where I am going
wrong.
> > >
> > >  > >
> > > $db_name = "db1";
> > > $table_name = "user";
> > >
> > > $connection = @mysql_connect("localhost", "user", "password") or
> > > die("Couldn't connect.");
> > >
> > > $db = @mysql_select_db($db_name, $connection) or die("Couldn't select
> > > database.");
> > >
> > > $sql = "UPDATE $table_name
> > > SET
> > > name = \"$name\",
> > > lname = \"$lname\",
> > > mobil = \"$mobil\",
> > > email = \"$email\",
> > > url = \"$url\",
> > > WHERE id= \"$id\"
> > > ";
> > >
> > > $result = @mysql_query($sql,$connection) or die("Couldn't execute
> > query.");
> > >
> > > ?>
> >
> > How about NOT masking the error message by using mysql_query(), instead
of
> > @mysql_query(). And instead of using die(), use echo mysql_error().
> >
> > --
> > Jason Wong -> Gremlins Associates -> www.gremlins.biz
> > Open Source Software Systems Integrators
> > * Web Design & Hosting * Internet & Intranet Applications Development *
> >
> > /*
> > A rolling stone gathers no moss.
> > -- Publilius Syrus
> > */
> >
> >
> > --
> > 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 General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: Populating form value fields.

2002-12-11 Thread liljim
Hi Steve,

you will need to use mysql_fetch_* on the result (where * might be object,
row, array, assoc):

$query = "SELECT * FROM products WHERE
ItemCode='$ItemCode'";
$result = mysql_query($query)
// for debug
or die("Error in query "$query". MySQL said: " .
mysql_error());
$row = mysql_fetch_assoc($result);

Then the form:






Check the manual for more details.

James

"Steve Jackson" <[EMAIL PROTECTED]> wrote in message
002b01c2a128$8c367c60$[EMAIL PROTECTED]">news:002b01c2a128$8c367c60$[EMAIL PROTECTED]...
> I am having problems populating form fields. Here is my code:
> //$ItemCode is passed to the page with this code
> $mysql = mysql_query("SELECT * FROM products WHERE
> ItemCode='$ItemCode'");
> $result = mysql_query($mysql);
>
> Then the form:
> 
>  class="kapea">
>  class="kapea">
>  class="kapea">
> 
>
> I have tried numerous ways to use $result to get these values to appear
> but am stuck. How therefore do I select everything from the database
> sorted by ItemCode and then displayed in a form as shown above.
>
> Regards,
>
> Steve Jackson
> Web Developer
> Viola Systems Ltd.
> http://www.violasystems.com
> [EMAIL PROTECTED]
> Mobile +358 50 343 5159
>



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




[PHP] Re: Beginner question : Removing spaces in forms

2002-12-13 Thread liljim
Hi Andrew,

"Andrew Wilson" <[EMAIL PROTECTED]> wrote in message:
>
> Hay guys i was wondering if there was a form parameter of something
> equivalent for input text boxes that when a user enters a number or series
> of numbers that it removes the spaces.
> If there is no alternative how would you go about solving this issue.


Am I right in thinking that you want the form input variable to contain
numbers only? If so, you could simply do this:

$variable = preg_replace("![^0-9]!s", "", $variable);

Which would strip out everything that's not numbers.

OR, are you expecting strings like:

"Here's a number you can call for tech support: 12345 6789 - be patient,
they take *forever* to answer!"

If so, you could probably craft some regular expression up to remove the
spaces.


James



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




[PHP] Re: mysql_num_rows

2002-12-18 Thread liljim
Hi John,

"John Taylor-Johnston"  wrote in message:
> I use $mycounter, not saying it is pretty. But if you have a whole bunch
of stuff deleted, your last id might be worth a lot more than the actual
number of rows.
>
> $myconnection = mysql_connect($server,$user,$pass);
> mysql_select_db($db,$myconnection);
>
> $news = mysql_query('select * from '.$table.' where '.$where.' order by id
asc');
>  $mycounter = 0;
>  while ($mydata = mysql_fetch_object($news))
>  {
>   $mycounter++;
>  }

Have you ever considered just doing a count()?

$count = @mysql_query("select count(*) from [table(s)] where [criteria
[group by something]]");
$total = mysql_result($count, 0);

That will return the number of rows in your table(s). It's also much quicker
and less resource intensive, particularly with large datasets. :)

James



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




Re: [PHP] Re: mysql_num_rows

2002-12-18 Thread liljim
I would also tend to do a count(*) as well as the main query if I intend to
use pagination (with the help of LIMIT in the main query).

Suppose, for example, you're limiting to 30 news posts per page, and from
calculations there are only 2 pages that fall into the criteria, then trying
to bring the result set back on page 3 when it doesn't "exist" will result
in a warning. Also, you'll want to know how many pages of the news post
there are...

Brief Example (assuming $page has already been validated as an integer):

$num = 30; // per page
$total = 49; // result from count(*)
$total_pages = ceil($total/$num);
if($page > $total_pages)
{
$page = $total_pages;
}

// Main query.
// "select [whatever] from [table(s)] where [criteria] [whateverelse] limit
" . (($page*$num)-$num) . ",$num;

James

"Philip Olson" <[EMAIL PROTECTED]> wrote in message
Pine.BSF.4.10.10212181637090.4483-10@localhost">news:Pine.BSF.4.10.10212181637090.4483-10@localhost...
>
> First, there is no reason to do mycounter like this
> when mysql_num_rows() will work perfectly.  It's not
> based on any certain column numbers or primary keys.
> Although if you're suggesting this method to simply
> print 0-n in the loop (as users may want to know the
> row number of output not any id number) then that's
> good altough it's not really a counter in this case.
>
> Second, we assume this person wants a count for
> informational purposes, to go along with the
> data in which case mysql_num_rows() is your best
> bet.  It means having a count before the data is
> printed/used.  And checking the number or rows
> returned before fetching is a form of error handling
> as well as if it equals 0 than there is no data to
> fetch.  But if one ONLY wants a number of rows count,
> doing SELECT count(*)... works great as suggested
> below.
>
>
> Regards,
> Philip Olson
>
>
> On Wed, 18 Dec 2002, liljim wrote:
>
> > Hi John,
> >
> > "John Taylor-Johnston"  wrote in message:
> > > I use $mycounter, not saying it is pretty. But if you have a whole
bunch
> > of stuff deleted, your last id might be worth a lot more than the actual
> > number of rows.
> > >
> > > $myconnection = mysql_connect($server,$user,$pass);
> > > mysql_select_db($db,$myconnection);
> > >
> > > $news = mysql_query('select * from '.$table.' where '.$where.' order
by id
> > asc');
> > >  $mycounter = 0;
> > >  while ($mydata = mysql_fetch_object($news))
> > >  {
> > >   $mycounter++;
> > >  }
> >
> > Have you ever considered just doing a count()?
> >
> > $count = @mysql_query("select count(*) from [table(s)] where [criteria
> > [group by something]]");
> > $total = mysql_result($count, 0);
> >
> > That will return the number of rows in your table(s). It's also much
quicker
> > and less resource intensive, particularly with large datasets. :)
> >
> > James
> >
> >
> >
> > --
> > 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] ereg.

2002-12-18 Thread liljim
Instead of:
(!ereg("^([a-zA-ZåÅäÄöÖ]{4,20})\$", $_REQUEST['f_name']))

Try:
(!ereg("^[a-zA-ZåÅäÄöÖ]{4,20}$", $_REQUEST['f_name']))

(You don't need the brackets unless you're wanting to get the output of the
matches, which in this case, it doesn't look as though you do)

Better still:
(!preg_match("!^[a-zåÅäÄöÖ]{4,20}$!is", $_REQUEST['f_name']))


James

"1lt John W. Holmes" <[EMAIL PROTECTED]> wrote in message
002301c2a6b3$a5a695f0$a629089b@TBHHCCDR">news:002301c2a6b3$a5a695f0$a629089b@TBHHCCDR...
> ^ is only NOT when it's the first character within brackets, [ and ].
Also,
> don't escape the $ at the end if you really want it to match the end of
the
> string. Right now your regular expression is matching a literal dollar
sign.
>
> As for the original question, it looks correct, providing you can have
those
> swedish characters in the brackets. What if you just simplify things and
> make your ereg look to match a single one of those swedish chacters? Will
it
> validate correctly if that's all you pass? Play with taking them in and
out
> and see what works.
>
> ---John Holmes...
>
> - Original Message -
> From: "Wico de Leeuw" <[EMAIL PROTECTED]>
> To: "Anders Thoresson" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
> Sent: Wednesday, December 18, 2002 11:26 AM
> Subject: Re: [PHP] ereg.
>
>
> ^ is not in this case
> Try
> if(!ereg("^([a-zA-ZåÅäÄöÖ]{4,20})\$", $_REQUEST['f_name'])) {
>
> Added the $ at the end else the could be more then 20 chars
>
> Greetz
>
> At 17:20 18-12-02 +0100, Anders Thoresson wrote:
> >What's wrong with the following regular expression? As far as I can se,
> >only alphabetic characters including the special swedish ones, should be
> >let through, but whatever character passed on in $_REQUEST['f_name']
> >passes the test?
> >
> > if(!ereg("(^[a-zA-ZåÅäÄöÖ]{4,20})", $_REQUEST['f_name'])) {
> > error("Your first name should be between 4 and 20
> > alphabetic characters");
> > }
> >
> >The next one, used to check valid birthday dates, work. And I can't see
> >where they differ!
> >
> > if(!ereg("([0-9]{4})-([0-9]{2})-([0-9]{2})",
> $_REQUEST['birthday']))
> >
> >Br,
> >
> >   Anders
> >
> >
> >--
> >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] Re: Code contents of a function

2003-01-03 Thread liljim
Output buffering functions sound like something you could use:

\n";
 }

 function DoStuff()
 {
  echo "Something\n";
  echo "Something else\n";
  OtherStuff();
 }

 // Start output buffering.
 ob_start();

 // Grab the content.
 DoStuff();
 $content = ob_get_contents();

 // Finish up.
 ob_end_clean();

 // What to do with $content?
 echo "Content is: " . $content . "\n";

?>

However, this could get messy and might not be what you're really after. If
you're just wanting to return values from your functions, use return:

function OtherStuff()
{
return "Monkey!\n";
}

function DoStuff()
{
$output = "Something\n";
$output .= "Something else\n";
$output .= OtherStuff();

return $output;
}

$content = DoStuff();

echo "Content = " . $content;

would have a similar effect to the output method above.

Anyway, further reference for you on output buffering can be found here:
http://www.php.net/manual/en/ref.outcontrol.php

-James


"Shawn McKenzie" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> I have a script with some functions and within the script I want to read
the
> code from one of the functions into a string.
>
> Example:
>
> function myfunction() {
> echo "something";
> echo "something else";
> someotherfunction();
> }
>
> I want to read:
>
> echo "something";
> echo "something else";
> someotherfunction();
>
> into a string.
>
> Any ideas??? TIA
> -Shawn
>
>



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




Re: [PHP] Months of the year

2003-01-06 Thread liljim
Another solution:

 $month_now = date("n");
 echo "\n";
 for($i=$month_now, $j=0; $i<=($month_now+12); $i++,$j++)
 {
  echo "" . date("F Y", mktime(0, 0, 0, $month_now+$j, 1, date("Y"))) .
"\n";
 }
 echo "\n";

This will start the month's dropdown on the month of the year through to the
month of the following year, e.g. January 2003 to January 2004, February
2003 to February 2004, etc.

James



"David Freeman" <[EMAIL PROTECTED]> wrote in message
006e01c2b56e$d559fe30$0b0a0a0a@skink">news:006e01c2b56e$d559fe30$0b0a0a0a@skink...
>
>  > How do I create a drop down list that automatically
>  > generates a list of months for the next 12 months upto and including
> this month
>
> This would do it...
>
>  
>$curr_month = date("n", mktime());
>
>  for ($x = 1; $x <= 12; $x++)
>  {
>$month_name = date("F", mktime(0, 0, 0, $x, 1, 2002));
>if ($x == $curr_month)
>{
>  echo "  $month_name\n";
>} else {
>  echo "  $month_name\n";
>}
>  }
>  ?>
>  
>
>
>



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




[PHP] Re: Odd Parse Error

2003-03-24 Thread liljim
You have a curly brace, where you should have a square bracket:

> if ($values{$i] != 0){ //line 137

if($values[$i]) {


James

"Shaun" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi,
>
> Using the following code i get a parse error for line 137, and i cant see
> anything wrong with it, i would be very grateful for someones help here!
>
> if ($num > 0){
>   if ($values[$i] == 0){
> $query = "DELETE FROM WMS_Allocatations WHERE User_ID =
> '".$_GET[user_id]."' AND Project_ID = '".$fields[$i]."'";
>   }
> } else {
>   if ($values{$i] != 0){ //line 137
> $query = "INSERT INTO WMS_Allocatations (User_ID, Project_ID) VALUES
> ('".$_GET[user_id]."', '".$fields[$i]."')";
>   }
> }
>
> thanks in advance for your help
>
>



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



[PHP] Re: When to use htmlentities()

2003-03-24 Thread liljim
If you store your text "htmlentitied" in the database, you will need to
apply htmlentities to the search string, but not when you bring the data
back from the database tables (to either display in the text editing screen,
or the normal viewing screen. Example:

"; ?>


That will not bring a desirable result, without applying htmlentities():


I prefer to store text as-is in the database, then perform htmlentities when
retrieving from the database. I tend to keep other text manipulation to
basic one-time tasks, like word breaking (for big chunks of words),
multi-space removal, etc.

James

"Rotsky" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Okay, I'm starting to tie myself in knots with this:
>
> Part of my site carries feature articles held in a MySQL database. I've
> written an admin page that allows me to edit the articles in an HTML form
> before saving them to the database (using INSERT or UPDATE as
appropriate).
>
> On the site, I want users to be able to search using keywords in the
> articles.
>
> Now, all of this is basically working, but I'm not sure quite what to do
> about special characters. If I use htmlentities on the data when writing
it
> to the database, then an ampersand will be stored as & and this will
> display fine. But then I guess I need to similarly treat search strings if
> users' queries are to match properly. Also, if I pull the article into the
> editing form, I guess I need to reverse the process with
> html_entity_decode() before displaying and editing it, which is getting a
> bit convoluted.
>
> Is there any reason why I shouldn't store characters in their natural form
> in the database - (eg, store '&' as '&' rather than '&') and then just
> use htmlentities to display the text?
>
> I'd be grateful for any opinions.
>
>



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



[PHP] Re: File manipulation tutorials / helpful resources

2003-03-24 Thread liljim
Tony, try searching the archives - the regular expression that's required to
get the stuff between the  tags has been asked many, many times
before.

Here's a quick bit of code that might get you started:

http://www.yahoo.com/";;
$their_text = implode("", file($file));

# now let's get our match between the body tags.
if(!preg_match("!]+>(.*)!is", $their_text, $matches))
{
 # No matches?
} else
{
 $my_text = $matches[1];

 # Copy to temp file first
 $fp = fopen($temp_file, "w");
 fwrite($fp, $my_text);
 fclose($fp);

 if(filesize($temp_file) > 0)
 {
  # We probably got some good text.
  copy($temp_file, $myfile);
 } else
 {
  echo "Something flakey's happened.\n";
 }
 unlink($temp_file);
}

?>

Have a look at phpbuilder.net for tutorials on this sort of thing - I seem
to remember having seen some tutorials there on this sort of thing not so
long back.

Points of reference:
http://www.php.net/file
http://www.php.net/fopen
http://www.php.net/fread
http://www.php.net/fclose
http://www.php.net/fwrite
http://www.php.net/preg_match
http://www.php.net/preg_replace


James

"Tony Crockford" <[EMAIL PROTECTED]> wrote:
> Hi
>
> What I'd like to do is open an html file, strip out the content between
> the  tags so that I can insert it into my own template.
>
> Has anyone got any good resources or tutorials I could read to help me
> accomplish this simple sounding task.
>
> I have no idea where to start! ;o)
>
> Thanks everyone.
>
> Tony
>



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



[PHP] Re: problems with rename() - permission denied

2003-03-25 Thread liljim
"Christian Rosentreter" wrote:

Hi Christian,

> I've a small problem, which mades me crazy... :\
>
> I'm trying to rename() a swapfile to real destination file (atomic
update).
> It works on differnt environments very well. Sadly not on my ISP-server
> I've added an "chmod($swapfile,0777)", but this has not solve the problem.
> The directories have all FULL access (read, write, etc.). The destiniation
file
too. I don't want 2 use the copy/unlink solution Do anyone have an idea?
>
>/* this fails with "Permission denied" */
>rename($swapfile,$filename);
>
>/* ... but this works */
>copy($swapfile,$filename);
>unlink($swapfile);

I'm just speculating, but it's possible that your ISP is running from
multiple machines: i.e. several webservers feeding off one fileserver. I had
a similar problem with one of the sites that I work on, and that was the
case. Might be worth asking your ISP if this is the case. The only solution
in my case was to go the copy() unlink() way. It's not as if it's a huge
workaround. ;)

James



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



Re: [PHP] question about Location

2002-09-06 Thread liljim

Are you needing to output anything to your users before the page is sent to
this new page?  If not, then simple answer, don't send output before
redirecting.

Brief example (coming from a submitted form)






-James

"Meltem Demirkus" <[EMAIL PROTECTED]> wrote in message
03ef01c2558e$923180f0$5583@hiborya">news:03ef01c2558e$923180f0$5583@hiborya...
> I tried , but it is giving this error:
>
> Warning: Cannot add header information - headers already sent by (output
> started at C:\FoxServ\www\debugger\project_module\project_update_.php:2)
in
> C:\FoxServ\www\debugger\project_module\project_update_.php on line 37
>
> the line 2  is   
>
> and  start_html.php includes:
>
> 
> 
> 
> 
>  
> 
> 
> 
>
>
> and line 37 is the header I wrote  ?>
>
>
> - Original Message -
> From: "Marek Kilimajer" <[EMAIL PROTECTED]>
> To: "PHP" <[EMAIL PROTECTED]>
> Sent: Friday, September 06, 2002 12:55 PM
> Subject: Re: [PHP] question about Location
>
>
> >  doesn't mean output unless you use echo or print or whatever to
> > output from there anything.
> > Just use header("Location: yournewpage.php"); at the end.
> >
> > Meltem Demirkus wrote:
> >
> > >>I mean  I made a page with php and other stuff..And there is form
.When
> I
> > >>click on okbutton  php is dpoing what it should . But after want the
> page
> > >>
> > >>
> > >to
> > >
> > >
> > >>come to another link.I asked that before and they told me that ..
there
> > >>
> > >>
> > >must
> > >
> > >
> > >>be no uotput but I am using  which means  output..
> > >>
> > >>so I dont know what to do..
> > >>meltem
> > >>
> > >>
> > >>- Original Message -
> > >>From: "Brad Bonkoski" <[EMAIL PROTECTED]>
> > >>To: "Meltem Demirkus" <[EMAIL PROTECTED]>
> > >>Cc: <[EMAIL PROTECTED]>
> > >>Sent: Friday, September 06, 2002 12:36 PM
> > >>Subject: Re: [PHP] question about Location
> > >>
> > >>
> > >>
> > >>
> > >>>Not quite sure what you are getting at here?  A hyper link would
direct
> > >>>the user to another page :-)
> > >>>If you mean after a timeout/auto-magically perhaps you can try meta
> > >>>
> > >>>
> > >>refresh:
> > >>
> > >>
> > >>>http://www.htmlhelp.com/reference/html40/head/meta.html
> > >>>
> > >>>HTH
> > >>>-Brad
> > >>>
> > >>>Meltem Demirkus wrote:
> > >>>
> > >>>
> > Is there anyway  to direct my page to another after the php and
output
> > process work on the page?
> > 
> > thanks
> > meltem demirkus
> > 
> > 
> > 
> > 
> > 
> > >>>
> > >>>
> > >>>
> > >
> > >
> > >
> > >
> >
> >
> > --
> > 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] Source code

2002-09-06 Thread liljim

I might be missing something, but Wouldn't this suffice?
: http://www.php.net/manual/en/function.highlight-file.php

Maintains formatting *and* colours things up nicely.


-James

"Lallous" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> I think it is also good to fetch $mem as:
>
> $fp = fopen('index.htm', 'r');
> $mem = fread($fp, filesize('index.htm'));
> fclose($fp);
>
> that will keep index.htm formatted as is.
>
> "Adrian Murphy" <[EMAIL PROTECTED]> wrote in message
> 001b01c2559f$aa8f3c30$1a8f43d9@ADE2">news:001b01c2559f$aa8f3c30$1a8f43d9@ADE2...
> > add nl2br() to make it look pretty e.g
> >
> > 
> >  > $mem = join('', file('index.htm'));
> >
> > $mem = htmlspecialchars($mem);
> > $mem = nl2br($mem);
> > echo $mem;
> > ?>
> > 
> > - Original Message -
> > From: "Roman Duriancik" <[EMAIL PROTECTED]>
> > To: "PHP-General" <[EMAIL PROTECTED]>
> > Sent: Friday, September 06, 2002 11:53 AM
> > Subject: [PHP] Source code
> >
> >
> > > How I show in IE source code of html page with php ?
> > >
> > >
> > > roman
> > >
> > >
> > > --
> > > 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] Re: HTML formatting

2002-06-28 Thread liljim

Hello,

I wrote this function:

!is", "",
$var);
 $var = preg_replace("!!is", "", $var);
 $var = str_replace("", "", $var);
 $var = str_replace("", "", $var);
 $var = str_replace("", "", $var);
 $var = str_replace("", "", $var);

 return $var;
}

$variable = CleanUpHtml($variable);
echo $variable;

?>

And it outputs:





In Waste Management:


Who collects my waste?

Collection Authority

District Councils


Who deals with disposal?

Disposal Authority

County Council


Who plans for the provision of waste sites?

Planning Authority

County Council


Who \'polices\' the waste sites? 

Regulation Authority
 

Environment Agency

Which I guess is what you were wanting? :)

James

"Bb" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> I have assembled a rich text html editor for the web and the code returned
> can be quite horrid.
>
> When pasteing from word (as our client wants to), the code returned looks
> something like this:
>
> 
>
> 
> 
> In Waste Management:
> 
> 
> Who collects my waste?
> 
> Collection Authority
> 
> District Councils
> 
> 
> Who deals with disposal?
> 
> Disposal Authority
> 
> County Council
> 
> 
> Who plans for the provision of waste sites?
> 
> Planning Authority
> 
> County Council
> 
> 
> Who \'polices\' the waste sites? 
> 
> Regulation Authority
>  
> 
> Environment Agency
>
> Which is grossly OTT.
>
> I would like to extract all the data from a tag and put back in the buts i
> want; i.e, get rid of all properies except things like colspan and
rowspan,
> etc.
>
> I wrote this simple routine to take out ALL the properties but this mucks
up
> a lot!
>
> $str = preg_replace("/]*)>/i","\\1",$str);
> $str = preg_replace("/]*>)/i","\\1",$str);
> $str = preg_replace("/]*)>/i"," bordercolor='#66' cellpadding=3 cellspacing=0>\\1",$str);
>
> can anyone help?
>
>



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




[PHP] Re: HTML formatting

2002-06-28 Thread liljim

Actually, I just threw in this amendment:

function CleanUpHtml($var)
{

 $var = preg_replace("!!is", "",
$var);
 $var = preg_replace("!!is", "", $var);
 $var = str_replace("", "", $var);
 $var = str_replace("", "", $var);
 $var = str_replace("", "", $var);
 $var = str_replace("", "", $var);

 preg_match_all("!<(/?t.*?)>!is", $var, $output);

 if (count($output[0]) > 0)
 {
  for($i=0; $ihttp://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: strange php output

2002-07-10 Thread liljim

Calvin,

this:
(!$page=="datetime")

(as I interpret it, that means if $page is false, and it's equal to datetime
(which should, in this context, also be false))

looks like it should read:
($page!="datetime")

James



"Calvin Spealman" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> I'm trying to do a little trick with my new site.  i have one main php
> script, index.php which includes the header and footer scripts and the
> page script between them.  the page script is determined by $page, which
> is set to "main" if it doesnt exist already.  $page . ".php" is then
> included.  I have one other page so far, "datetime.php".  I wanted to
> let datatime run itself by including the headers and footers on its own
> if it wasnt included by index.php.  so, i add this to the top and
> similar code at the bottom (replaced header with footer):
>
>  if (!$page=="datetime") // Not using index.php
> {
> include("header.php");
> }
> ?>
>
> this code works when datetime.php is included by index.php, but on its
> own the script just outputs .  Even ignoring
> the xhtml code outside the php code in the file.  its like the entire
> file is ignored.  i really have no clue why.  anyone else have one?
>



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




[PHP] Re: Problem on file_exists()

2002-07-16 Thread liljim

Jack,

Probably because of the space in the directory "dealing room" - you'd be
best advised to avoid spaces in directory names.

~James

"Jack" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Dear all
> I had a folder which the path is : (\\nedcoraa\pdf_reports\dealing
> room\report) it stores a lot of PDF reports in there.
> I'm trying to use the file_exists() function to detect if a specific file
> exist in this folder, but i got a problem is :
> It seems that php can go through (\\nedcoraa\pdf_reports) but it can't go
> through (dealing room) folder. i had made test on it, i moved a file into
> (\\nedcoraa\pdf_reports), then php can detect it, but if i move it to
> (\\nedcoraa\pdf_reports\dealing room), then it can't detect the file! why?
>
> I'm using php in windows NT IIS environment!
>
> Please help me!
>
> --
> Thx a lot!
> Jack
> [EMAIL PROTECTED]
>
>



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




[PHP] Re: ^k ? -- how do I match that?

2002-07-16 Thread liljim

Hi Jimmy,

In many cases, I'd go for a regex, though with this (because it's just a
straight replacement), I'd just use str_replace (and since about the closest
thing to a vertical tab would be a new line in html, use that as the
replacement):

$string = str_replace("^K", "\n", $string);

James


"Jimmy Brake" <[EMAIL PROTECTED]> wrote in message
1026765137.15017.151.camel@linux">news:1026765137.15017.151.camel@linux...
> Hi!
>
> I keep getting that evil little character ... ^k  from mac users (pre X)
> and I need to remove it. Does anyone know how to remove?
>
> This site has that character as a vertical tab. This character is what
> is used in MS Excel when people hit return inside a cell. If they copy
> and paste that into a form its ok, but when I export that data to a csv
> it gets ugly.
>
> http://www.robelle.com/smugbook/ascii.html
>
> Thanks in advance!
>
> Jimmy
>



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




[PHP] Re: help using ereg_replace()

2002-01-14 Thread liljim

Hello Erik,

> Hello everyone,
>
> I am trying to learn how to use ereg_replace(), but I don't seem to be
> doing it correctly.
>
> "$phone" is a 10-digit string.
>
> I want to perform the following:
>
> $phone = ereg_replace(".{10}", "[part where I am confused]", $phone);
>
> I would like the output to be
>
> $phone = "(555) 555-";

I would use preg_replace to do this.



The parentheses in the first part of the expression capture what you want.
The stuff between the [and] is a characterclass (in this instance 0 through
9).
The stuff between the curly braces is min,max.

So.
([0-9]{3,3}) Match 0 through 9 a minimum (and max) of three times
([0-9]+) - match at least once.

Hence the number becomes:
($1) $2-$3
($1) = stuff in first parentheses (three digits) - this case, (555)
followed by a space
followed by the next three digits
followed by a dash
followed by whatever's left.
Note that in the second part of the expression, parentheses lose their
"special meaning", and can be used as regular characters (as can the other
metacharacters).

You will want to make sure that the numbers when inputted are in the format
you want them when you bring them back out of the file / db whatever -

if (!preg_match("/^[0-9]{10,10}/", $input)) {
// We need 10 numbers!
}

Hope that helps.

James




-- 
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] Re: help using ereg_replace()

2002-01-14 Thread liljim

Hi Erik,

> Thanks for the advice (and especially the explanation!) -- I note that
> you chose the Perl regexp engine rather than the "e" regexp engine
> (POSIX?).  Quite a few people recommended O'Reilly's "Mastering Regular
> Expressions" over the weekend.  Does anyone know if it covers the Perl
> syntax*?  This seems like a good book to learn more.

The book (though going into examples using perl mainly) gives you a general
grounding in regular expressions - I learned php before perl, and
javascript, though the book has equipped me equally well for all three.  I
love it, and would recommend it for anyyone who's even vaguely interested in
regexes.

James


-- 
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] Re: seems easy...

2002-01-24 Thread liljim

Hi Justin,

$string = substr($string, 0, 5000) . " text too long.";

?

http://www.php.net/substr

James

"Justin French" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hi,
>
> Really simple, but can't see which funtion to use in the manual.
>
> I want to take a user-inputted string $text, and IF it's length is more
> than $limit, trim it to the limited length, and then tack on some kind
> of "... text cut (too long)" thing on the end.
>
> I'm only missing one bit (line4):
>
> 1  $limit = "5000";
> 2  if(strlen($text) > $limit)
> 3{
> 4
> 5$text .= "...sorry, text was too long";
> 6}
>
>
> Or is it hard than that?
>
>
> Justin French



-- 
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] Re: delete a file from the server

2002-01-24 Thread liljim

Hi Tommy,

use unlink()

$filename = "mypic.jpg";

unlink($filename)
or die("Something's barfed");

James

> How can i delete a file from the server in PHP




-- 
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] Re: Help with regular expressions

2002-01-25 Thread liljim

Hi Daniel,

"José daniel ramos wey" ...
> Hi! I´m new to regular expressions, and it seems to be an art to make it
> work as expected.
>
> I´m trying to remove all "single-line" comments from an string - that´s
> everything after "//" to the end of a line. I expected that this would do
> the job: ereg_replace("//[[:alnum:]]*\n","",$string), but it didn´t work.
>
> Any tips?

First off, IMO, you're better off using pcre regex functions than the posix
ones:

http://www.php.net/preg_replace



Your regex is basically saying this:
//[[:alnum:]]*\n

Match anywhere in the string (you have no anchor as to where the // should
start), consume anything that is alphanumeric (0 through 9, a through z), as
many times as they occur, followed by a new line.  Thus, your regex would
consume stuff like this:

//sdfdfffsdfsdfsdd12345678900987sdfsdbfs

but not

//
sdfdfffsdfsdfsdd12345678900987sdfsdbfs

or

// this is a comment.

as for my example, I'm using exclamation marks as the delimiters, the m
modifier which matches $ at the end of every newline, and ^ at the start of
every new line.

So:
!^//.*$!m

Means

^ at the start of the line
// if there are two of these
.* match everything
$ up to the end of the new line

and replace it with nothing.

Check the pattern modifiers etc in the manual.

HTH

~James




-- 
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] Re: regexp to substitute incremental strings

2002-01-25 Thread liljim

Hi mweb,

try this:


blah blah blah some text, html markup...

blah blah again";

$string = preg_replace("//i", "", $string);

echo nl2br($string);

?>


~James

"Mweb" <> wrote in message ...
Hello,

What is the right regexp to handle this, either in a while loop (how?)
or all by itself? The closer I've come to the solution is:





-- 
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] Re: Ereg/replace/i/ or something ??

2002-01-30 Thread liljim

Hi Bart,

> I want to check the data from a form-field if it excists only of digits
> (0-9) and nothing else.
>
> How do I use the ereg()-function for this?

Well, I prefer the preg_functions

if (!preg_match("/^[0-9]{10}$/", $string)) {
// contains stuff other than numbers, or is less than 10 digits in length.
}

You could also just use is_int()
http://www.php.net/manual/en/function.is-int.php
and strlen()
http://www.php.net/manual/en/function.strlen.php


>   >>  ereg("[0-9]",$cust_tel, $cust_tel);  <<
>
> It is also to turn it around but then the pattern will get larger because
it
> has to contain:
>  / "'.,-)(*&^%# a-z A-Z and so on...
>
> The field has to be 10 digits long and has to contain only digits!!!

Huh?

If you just want digits, then where've those other patterns come from?  Do
you mean you want anything BUT numbers?

Ok:
if (!preg_match("/^[^0-9]+$/", $string_without_numbers)) {
// string contains numbers
}

otherwise, please clarify.

James



-- 
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] Re: Yet another regex question

2002-02-04 Thread liljim

Hello, Simon

"Simon H" wrote in message...
> I'm trying to validate an input form, for database INSERT/UPDATE.  I'm
> looking for a couple of Techniques and I cant seem to find examples
> anywhere:
>
> 1. Validate Alpha Text with spaces, such as NAME, CITY, STATE, but limit
the
> length of each one separately, and remove unwanted characters like
> '@!"£$%^&*() etc that might mess with the SQL.

Alright, clearup before you insert. That's my first bit of advice.
Here's a function for you.

function ClearUnwanteds($string) {
$string = preg_replace("/[^a-zA-Z0-9 ]/", $string);
$string = trim($string);
return $string;
}

This will replace (when invoked, like this: $string =
ClearUnwanteds($string) ) the characters you don't want, and then trim the
string.  Then you can do:

if (strlen($string) < /*enter minimum characters*/) {
// error
}

> 2. As above but alphanumeric with spaces etc. for say ADDRESS1 ADDRESS2
> POSTCODE, etc.

Hmm.. isn't that what you wanted for your previous problem?

> 3. Validate DATE/TIME input to DD-MM- HH:MM:SS or D-M- H:M:S, or
any
> combination, but only allow valid dates and times, or as close to it as
> possible.

You should pick a format, and stick to it, then form a function around the
format you've chosen - or look up some classes available for use on the net.
Since you're storing the data in a MySQL database, you may as well check the
date in the format it's stored in your db in the date (-MM-DD) or
datetime (-MM-DD HH:MM:SS) formats MySQL uses I would go for select
boxes with the day, month and year specified, then use something like
checkdate() to check the date on these variables, then "merge" them
(can't think of a better word) to form your date - i.e.

if (CheckDate($month, $day, $year)) {
// -- if ok, $date = $year . "-" . $month . "-" . $day;
} else {
// failure
}

 I have formed some functions that I've made available (somewhere), if you
need them I can probably drag them out and give you the urls.

> 4. Validate MONEY input...numeric with 2 decimal places only.

What currency?  You're using a UK email address, but you've specified
"STATE" in one of your other regex "wanteds", which is more typical of the
US address format.

> Also, what is the best way to allow some fields to be empty, like
ADDRESS2,
> but if they have data, then validate it.

if (!emtpy($field)) {
// perform validation.
}

???

> I've tried several times to do these myself using eregi, but when I test
it,
> the validation fails in some way...I'm shooting in the dark tho, and don't
> really understand regex just yet, or probably the majority of PHP for that
> matter.

Well, ok. But that's what you're here for, right? :)

> Thankfully I've got an email one... it was easy to find, since that's what
> all examples are geared for.  My application is for updating a DB with
SQL,
> and I cant find anything suitable.

Then your'e looking in the wrong places (and more specifically, looking at
things from the wrong perspective - regex's can be applied to pretty much
anything (though, there are occassions when using them is overkill))!

> If there is any other advice for data input into DB's regarding security,
> I'd really to hear it.

bvr's advice is good - read up on what he's suggested. :) Oh, and there are
the manual entries (for which I've forgotten the addresses).

Good luck!

~James



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




[PHP] Re: Yet another regex question

2002-02-04 Thread liljim

Hello again,

> This is excellent.  If you don't mind digging out your functions, I'd much
> appreciate it...

I'll have a look tomorrow.

> The previous question was for alpha only, no numeric ...names dont have
> numbers, but addresses usually do.

Alright, well:

[a-z] matches a through z
[A-Z] same, upper case
[0-9] yup, zero through 9
[ ] space

Look up the pattern modifiers, and the pattern syntax in the pcre section of
the manual):

if (!preg_match("/[a-zA-Z]+$/", $name)) {
// $name doesn't consist of characters within a-z or A-Z
}


> I'd got kinda mixed up there on the date thing...lol.  I have a javascript
> date picker thingy, but unfotunately it drops leading zeros on the dates
and
> times.  I think, however, your suggestion if pulldowns is much safer, but
> the date will be for MySQL or MS Access.  I think -MM-DD HH:MM:SS, as
> you suggested would be the answer, and I'll try to add the time into the
> $date variable.

Just out of curiosity, what are you using this for?  I mean, you might be
doing more work than you need to be doing.

> The currency is irrelevent here (although will UK£).  I just want the 2
> decimal places money format.  I have STATE above because thats what the
> field is in the databaseOn display it says state/county.

I see - check out number_format(), printf() and sprintf() in the manual -
this might already solve some of what you want, though I can't see why you'd
need two decimal places in a regex check :

$19.95 // one decimal
£19.95 // same
£19.95.1 // what the? :)

Can you elaborate as to why you need 2?


Alright, time for sleep.

Try and give a bit more info as to what you're using these for (and where,
if it's currently being used) your code is failing..

:)

Night

James


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




[PHP] Re: Exact string replacement...

2002-02-09 Thread liljim

Hello Desikan,

this should suit your needs.



~James

> Please help me out in the following...
>
>  $is='is';
> echo eregi_replace(" ".$is." "," ","This is a test string which contains
> is in dismissal");
> ?>
>
>
> Actually I want to replace "is" alone from the string and not all the
> words that contains is...




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




[PHP] Re: Maths Problem

2002-04-17 Thread liljim

Hello,

"Richard Meredith-Wilks" <[EMAIL PROTECTED]> wrote in
message B1CFE9307BACD211B071D11C344102A4E8E0@UKSTONTSRV3">news:B1CFE9307BACD211B071D11C344102A4E8E0@UKSTONTSRV3...
> > Hi,
> >
> > I have a maths question.
> >
> > I'm trying to create a html form where a user can enter formula in an
> > input box (e.g. '$a + $b - 10') and posts it to PHP.
> > The variables $a and $b are known but the formula can be changed on the
> > form (e.g. '$a / $b * 2').
> > I want PHP to take the text input, the formula and calculate the result
> > and display the results.




+
-
*
/








If the values are known, just hard code them. If not, you'll want to pay
closer attention to the user input.

It's not fully what you're after, but it's enough to get you started anyway.

James



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




[PHP] Re: ereg size limit???

2002-04-22 Thread liljim

Hi,


"Sp" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> I am trying to validate my input with ereg but I get the error "Warning:
> REG_BADBR" when I try over 255 characters.  Is there anyway around this?
>
> Works
> =
> if(eregi('^[A-Za-z]{1,255}$', "test sentence"))
>   echo "valid input";
>
> Doesn't Work
> 
> if(eregi('^[A-Za-z]{1,256}$', "test sentence"))
>   echo "valid input";


First off, you're using eregi (case insensitive), but defining a-zA-Z (a
through z, case insensitive) in your characters class. You could just use
ereg and leave the character class as it is, or drop the A-Z from the eregi
version.

Secondly, I'd amend your code to:
^[a-z]+$

And thirdly, I'd just use a combination of ereg / preg_* functions and
strlen.

if(preg_match("/^[a-z]+$/i", $string) && strlen($string) < 255)
{
echo "Whatever.";
}

I'm not sure why you're getting that error, but then again, I haven't
bothered reading up about it :)

James



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




[PHP] Re: RegEx and ?

2002-04-24 Thread liljim

Hi Berber,

you generally need to do some string replacements on the text you're using
to put through the match before you actually do the match (and same for
replacements).  Just have a look at the pattern syntax in the manual for the
characters you need to do the replacement on... e.g

$string = "Will this work?";
$criteria = "work?";

$criteria = str_replace("?", "\?", $criteria);

if (preg_match("/" . $criteria . /is", $string))
{
echo "Bingo.";
}

I usually make a function that will replace all the special characters. The
only one that stands out against the rest is the $, because escaped once in
a pcre function means that it is a variable - you need to escape it twice.
Here's some of what I tend to use (cut out a function - the rest of the
function won't mean much to you ;)):

  // Clear up the special characters in the $criteria.
  $criteria = str_replace("^", "\^", $criteria);
  $criteria = str_replace("[", "\[", $criteria);
  $criteria = str_replace("]", "\]", $criteria);
  $criteria = str_replace("*", "\*", $criteria);
  $criteria = str_replace("+", "\+", $criteria);
  $criteria = str_replace("{", "\}", $criteria);
  $criteria = str_replace("}", "\}", $criteria);
  $criteria = str_replace("?", "\?", $criteria);
  $criteria = str_replace("|", "\|", $criteria);

  // The $ is a little tricky, since it is used for end of string / line,
  // and for use with variables when escaped. It therefore needs two
  // backslashes.
  $criteria = str_replace("$", "\\$", $criteria);

  // We're using ! as a delimiter, so that must be replaced, too.
  $criteria = str_replace("!", "\!", $criteria);

There's probably bits missing from that, since that's from a script in
development, but you get the idea.

Hope it's of some help,

James

"Boaz Yahav" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
When i try to use preg_match on strings that have "?" inside them it
seems to not work.
Any ideas how to bypass this?

thanks

berber




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




[PHP] Re: RegEx and ?

2002-04-24 Thread liljim

What d'ya know. I should read the manual more regularly.

http://www.php.net/manual/en/function.preg-quote.php

~J



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




[PHP] Re: Trimming text

2002-04-24 Thread liljim

Hello Ashley,

]+>modified by.*?<\/span>\.$/is", "",
$string);
// remove the \. if it doesn't end in a full
stop^
?>

Try that.

James

"Ashley M. Kirchner" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
>
> I have a variable ($description) that contains text data (pulled from
an MySQL DB).  I need to delete the last few lines from that data.  Prior to
the data getting submitted to the DB (during a different routine), the
following information gets added:
>
> $description .= "\n\n< span class=gensmall >Modified by
".$userdata[username]."< /span >.";
> (spaces added so the tags don't get parsed)
>
> Later in the routine, that data gets pulled back up for modification
and I need to delete that last bit from it.  From the starting '\n' till the
end '< /span >.'...
>
> What's the best, and or easiest way to do this?
>
> --
> H | "Life is the art of drawing without an eraser." - John Gardner
>   +
>   Ashley M. Kirchner    .   303.442.6410 x130
>   Director of Internet Operations / SysAdmin. 800.441.3873 x130
>   Photo Craft Laboratories, Inc.. 3550 Arapahoe Ave, #6
>   http://www.pcraft.com . .  ..   Boulder, CO 80303, U.S.A.
>
>



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




[PHP] Re: Removing Irregular characters

2002-04-24 Thread liljim

Hello Liam,

varchar WILL work. Just ensure that you're applying addslashes() to the
input before putting it into the database.

http://www.php.net/addslashes

James

"Liam Mackenzie" <[EMAIL PROTECTED]> wrote in message
00a501c1eb6f$08a6f060$0400a8c0@enigma">news:00a501c1eb6f$08a6f060$0400a8c0@enigma...
> Hello
>
> I have a form that is to entered into a MySQL database.
> A couple of the feilds must contain irregular characters, such as
> (/\+;]{'.,<:"?>}|_~`)
>
> What MySQL Field type should I use?
> varchar doesn't work.
>
>
> Thanks, Liam
>
>
>



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




[PHP] Re: regular expressions help please

2002-04-30 Thread liljim

Hi Ed,

first example has been covered by others, so onto the next:

> Pulling a word between two other words without having to know what the
word
> is.  For example, pulling whatever word displays between "the" and
> "sky".  If the string was "the blue sky", the result would be the word
> blue.  If the string were "the green sky", the result would be the word
green.

I don't quite understand what you mean by "pulling", but this example will:
1. Take out any words if they exist.
2. Store those removed words into an array for you to use later, should you
need to see what was taken out.

Example 2\nOriginal string: " . $string . "\n";
if (preg_match_all("!the\s(.*?)\ssky!is", $string, $output))
{
 // Use an array to store all the matches.
 $saved = array();

 for($i=0; $iReplaced: " . $string . "\n\n";

if (!is_array($saved))
{
 echo $saved;
}
else
{
 echo "The following words were taken out of the pattern:\n";
 for ($i=0; $i\n";
 }
}

?>

There's nothing complicated about the match:
preg_match_all() - see manual
! delimiters !
the - first word
\s - space
(.*?) - everything up to next (non greedy)
\s - space
sky - word
i - case insensitive
s -  treat new lines (\n as .)

If you just want to rip stuff out, then you can use preg_replace():

$string = preg_replace("!(the)\s.*?(\ssky)!is", "$1$3", $string);

See the manual, or search these archives for further examples if you're
struggling Regexes (and when to use them) take a little getting used to,
 but they're definitely worth learning :)

Hope it helps.

James



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




[PHP] Re: Searching for any number in a mysql query

2002-05-21 Thread liljim

Hi,

try something like this:

"select [fields] from [table(s)] where [fieldtosearch] regexp
"^([1-9]{1}|10)";

~James

<[EMAIL PROTECTED]> wrote in message
003901c200b2$27ccff40$0100a8c0@JohnH">news:003901c200b2$27ccff40$0100a8c0@JohnH...
This isn't a one hundred percent PHP Q but here I go.

If I have the following query:
$query = "SELECT code FROM links WHERE ".$text." like '".$l."%' ORDER BY
sort_text";
and define the letter a letter i.e x.
it works fine.
I am not sure what to do if I want to say get something that starts with
(from one to ten).
I want to say all the numbers at once, not one at a time.
Any help appreciated,
JJ Harrison
[EMAIL PROTECTED]
www.tececo.com



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




[PHP] Re: Reverse mySQL date

2002-05-21 Thread liljim

Hello,

use DATE_FORMAT

"select date_format(datefield, '%d-%m-%Y') as mydate from table";

~James


<[EMAIL PROTECTED]> wrote in message
005e01c200b5$194184c0$0100a8c0@JohnH">news:005e01c200b5$194184c0$0100a8c0@JohnH...
How can I reverse the date coming out of mySQL?


ie 2002-05-21

becomes 21-05-2002

Can do it in the mySQL query or do I need to use PHP?

Thanks in advance,

JJ Harrison
[EMAIL PROTECTED]
www.tececo.com



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




Re: [PHP] Re: A stupid question...

2002-03-11 Thread liljim

Hi chuck,

use left()

assuming your column is called "name", then something like this will do:

$letter = "a";

$get = @mysql_query("SELECT * FROM table WHERE LEFT(surname, 1) = '$letter'
ORDER BY surname ASC");

That should get out all of the fields beginning with a or A and list them
alphabetically.

Hope that's of some help.


James

"Chuck "Pup" Payne" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> I want to sort by a letter in a colomn. Let say I want to sort the colomn
> last_name. I can do order by but I can do just the A's.
>
> http://www.myserver.com/mysort.php?Letter=A
>
> Like to create a link on a web "A" then sort only the last name are A.
>
> I hope that's helps. I can order by, but I can't so a sort like the
example
> above.
>
> Chuck Payne
> Magi Design and Support
>
>
> > on 3/10/02 9:42 PM, Cary at [EMAIL PROTECTED] wrote:
> >
> >> At 08:24 PM 3/10/02, Chuck \"PUP\" Payne wrote:
> >>> Hi,
> >>>
> >>> I not a newie but I am not a pro at mysql either. I want to do a query
by
> >>> letter(a, b, c..ect.). Is there a simple way to do it. I am writing in
PHP.
> >>> So can someone please so me the how.
> >>
> >>
> >> I'm not totally sure what your looking for. If you could elaborate a
little
> >> I am sure that one of us could help you out.
> >>
> >> Cary
> >>
> >>
> >>
> >
>



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




Re: [PHP] Re: A stupid question...

2002-03-11 Thread liljim

You're using the wildcard in the wrong place.

Should be

"like '$letter%'";

Or,

"left(column, 1) = '$letter'";

use a die() and mysql_error() to report problems to the browser:

$result =mysql_query("SELECT * FROM emply_info WHERE LEFT(Lname, 1) =
'$letter' ORDER BY Lname, Fname DESC",$db)
or die("Database error: " . mysql_error());

James



> $result =mysql_query("SELECT * FROM emply_info WHERE Lname ORDER BY Lname,
> Fname
> DESC LIKE'%$letter'",$db);
>
> $letter="a"
>
> That's what I tried.
>
> Chuck



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




[PHP] Re: replace digits

2002-03-19 Thread liljim

Hi Marc,

try this:

$string = preg_replace("/^41/", "0", $string);

http://www.php.net/preg_replace

/ and / = delimiters
^ = start of string (line in multiline mode)

So, it translates as, "replace a leading 41 in $string with 0".

..or try the ereg function, which has already been mentioned.

James


"Marc Bleuler" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hello all,
>
> Im trying to replace the first two digits (41) from a telephone no. with a
0
> (zero), like 41763334455 should end wit 0763334455. Anybody a idea howto?
My
> php programming experiance is not very high so if any body could provide a
> code example
>
> thank you very mutch for help
> Marc
>
>



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




Re: [PHP] Returning mutliple matches of a regex with preg_match()

2002-03-21 Thread liljim

Also, make sure that you make the match "ungreedy" with the U modifier, or
use:
(.*?)


James

"Niklas lampén"  wrote in message
000501c1d0aa$4a5d97f0$ba93c5c3@Niklas">news:000501c1d0aa$4a5d97f0$ba93c5c3@Niklas...
> preg_match_all();
>
>
> Niklas
>
> -Original Message-
> From: Stefen Lars [mailto:[EMAIL PROTECTED]]
> Sent: 21. maaliskuuta 2002 7:28
> To: [EMAIL PROTECTED]
> Subject: [PHP] Returning mutliple matches of a regex with preg_match()
>
>
> Hello all
>
> I have been scratching my head for the last two days about this regular
> expression problem. I would be really VERY happy if someone could help
> me!
>
> I have the following text in the file 'text.htm', for example:
>
> --
>
> 
> Cow, Cow, Cow, Cow, Cow
> Cow, Cow, Cow, Cow, Cow
> Cow, Cow, Cow, Cow, Cow
> a lot of lines
> 
>
> boring stuff - we are not interested in this
>
> 
> Chicken, Chicken, Chicken
> Chicken, Chicken, Chicken
> Chicken, Chicken, Chicken
> more lines
> 
>
> more boring stuff - we are not interested in this
>
> 
> Rabbit, Rabbit, Rabbit, Rabbit
>
> 
>
> even more boring stuff - we are not interested in this
>
> 
> Pig, Pig, Pig, Pig, Pig
> 
>
> --
>
> I want to return all the stuff between  ...
> 
> in an array. One element per match. For example, for the above text, I
> would
> like to get back an array back like this:
>
> array(
> "Cow, Cow, Cow, Cow, Cow Cow, Cow, Cow, Cow, Cow Cow, Cow, Cow,
> Cow, Cow a
> lot of lines",
> "Chicken, Chicken, Chicken Chicken, Chicken, Chicken Chicken,
> Chicken,
> Chicken more lines",
> "Rabbit, Rabbit, Rabbit, Rabbit",
> "Pig, Pig, Pig, Pig, Pig"
> )
>
> I have been trying to do this with (many variations of) the following
> code:
>
> --
>
> 
> // open file
> $fd = fopen ("./text.htm", "r");
>
> // load contents into a variable
> while (!feof ($fd))
> {
> $content .= fgets($fd, 4096);
> }
>
> // close file
> fclose ($fd);
>
> // remove char returns and co.
> $content = preg_replace("/(\r\n)|(\n\r)|(\n|\r)/", " ",$content);
>
> // match agains regex -- this does not work correctly
> if
> (preg_match("/(.*)<\/P><\/BLOCKQUOTE>/i",$content,$matche
> s))
> {
> echo "";
> var_dump($matches);
> echo "";
> }
>
> ?>
>
> --
>
> For the above, var_dump() returns this:
>
> --
>
> array(2) {
>   [0]=>
>   string(556) " Cow, Cow, Cow, Cow, Cow Cow, Cow, Cow,
> Cow,
> Cow Cow, Cow, Cow, Cow, Cow a lot of lines   boring
> stuff - we are not interested in this   Chicken,
> Chicken, Chicken Chicken, Chicken, Chicken Chicken, Chicken, Chicken
> more
> lines   more boring stuff - we are not interested in
>
> this   Rabbit, Rabbit, Rabbit, Rabbit
>   even more boring stuff - we are not interested in
> this   Pig, Pig, Pig, Pig, Pig "
>   [1]=>
>   string(524) " Cow, Cow, Cow, Cow, Cow Cow, Cow, Cow, Cow, Cow Cow,
> Cow,
> Cow, Cow, Cow a lot of lines   boring stuff - we are
> not
> interested in this   Chicken, Chicken, Chicken
> Chicken, Chicken, Chicken Chicken, Chicken, Chicken more lines
>   more boring stuff - we are not interested in
> this   Rabbit, Rabbit, Rabbit, Rabbit
>   even more boring stuff - we are not interested in
> this   Pig, Pig, Pig, Pig, Pig "
> }
>
> --
>
> Clearly not what I want.
>
> Is my approach here incorrect? Or is it indeed possible to construct a
> regex
> to do what I want (with just one pass of the text)?
>
> Thank you in advance.
>
> :-))
>
> S.
>
>
>
>
>
>
> _
> Send and receive Hotmail on your mobile device: http://mobile.msn.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] Still REG EX

2002-03-25 Thread liljim

Have a look at this:

function ValidateUrl($url) {
 // Check the syntax
 if
(!preg_match("!((https?|ftp)://)(www\.)?([a-zA-Z0-9/\-]*)+\.([a-zA-Z0-9/\-]*
)+([a-zA-Z0-9/\-\.]*)?!", $url)) {
  return false;
 }
 // If it's correct, then try and open it
 if (!@fopen($url, "r")) {
  return false;
 }
 return true;
}

if (!ValidateUrl("http://www.yoursite.com";)) {
 echo "Invalid url";
} else {
 echo "It's there.";
}

Not particularly clean, but it seems to work ok.  Will check for http,
https, ftp, followed by an optional www. followed by numbers, digits,
hyphens etc. If it gets passed that check, then the function then attempts
to open the url. You may need to play around with it a little...

~James


"John Fishworld" <[EMAIL PROTECTED]> wrote in message
004001c1d2cc$caff60e0$04010a0a@fishworld">news:004001c1d2cc$caff60e0$04010a0a@fishworld...
> Okay good point but still why doesn't it work ?
>
> thanks
> john
>
>
> > On Sun, 24 Mar 2002, John Fishworld wrote:
> > > I'm still playing about trying to validate an url
> > > www(dot)something(dot)something !
> > >
> > > I thought this would work but know
> > >
> > > if (ereg("^(w{3})(\\.)([a-zA-Z]+)(\\.)([a-z]{2,4})$", $str))
> >
> > First of all, web server hostnames don't need to start with www.
Secondly,
> > they can have any number of components (separated by periods) from 1 to
> > dozens. Thirdly, the last term doesn't have to be 4 characters or less.
> >
> > > ([a-z]{2,4})$ = at least 2 leters eg de but upto 4 eg info
> >
> > .museum...
> >
> > miguel
> >
> >
>
>



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




[PHP] Re: reg-ex

2002-03-25 Thread liljim


"John Fishworld" <[EMAIL PROTECTED]> wrote in message
002301c1d3fa$b2c2f350$04010a0a@fishworld">news:002301c1d3fa$b2c2f350$04010a0a@fishworld...
> How can I change this to accept spaces as well ?
>
> (ereg("^[A-Za-zÀ-ÖØ-öø-ÿ]*$", $str))

Put a space in the character class.

~James



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




[PHP] Re: Trans_sid

2002-03-27 Thread liljim

Hi Rick,

I asked this same question to an ISP I'm with, and was told that it's only
possible through a re-compile. The way I got around it is this: I created a
function to check whether SID was present (it only is when the session is
first invoked, and from there on if the user doesn't have cookies enabled).
The function takes three arguments; type, url, and link text / image.
Here's how it looks:

// Function to auto append the session id to a link: takes the link and name
of link and
// the type of link (a=&, b=?) as arguments.
function AppendSessionId($link, $label, $type) {
 $display = "" . $label . "";

 return $display;
}

The type is for appending the SID onto links that already have a query
string. So if you did:

echo AppendSessionId("page.php?id=1", "Page 1", "a");

URL output would be:
page.php?id=1&session_id_variable_name=34567890

If the user has cookies enabled, ouput would simply be:
page.php?id=1

If you use type "b", then the sid is appended with a question mark (new
query string is started) for those users without cookies enabled:

echo AppendSessionId("page.php", "My page", "b");

output would be:
page.php for cookies enabled users and
page.php?session_id_variable_name=23456789 for those who cause us problems.

Hope that helps. If anyone's got a better solution, I'm all ears! :)

James

"Richard Baskett" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
Is there any other way of enabling trans_sid besides when compiling php?
Can I enable it in the php.ini file or .htaccess? And if so what would the
syntax be?  I've tried multiple things, but nothing seems to work..

If that's not possible is there a way of getting rid of the '?' in the url
when people have cookies enabled?  When cookies are not enabled the sid will
follow the '?' in the url since currently all my links have  at the
end.. So for example:

Please login

As you can see there will always be the '?' at the end of login.htm.. When
the surfer has cookies off it doesn¹t look bad, but when he has them
enabled.. It just looks strange :)

Thanks!

Rick

"A good head and good heart are always a formidable combination. But when
you add to that a literate tongue or pen, then you have something very
special" - Nelson Mandela




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




[PHP] Re: Regex Form Filter Help

2002-03-28 Thread liljim

Hello James,

"James Taylor" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> I have a site where users can type whatever they want in and it posts it
to a
> database.  I'm trying to eliminate whatever types of abuse I can think of,
> and, since I'm using nl2br on the posts, I'm afraid a user might just hold
> down enter for a couple of seconds and scroll everything off the page. I'm
> trying to figure out a regex pattern that searches for say, more than 5
 /> strings in a row, and anything after 5 gets stripped out.  Any ideas on
> how to possibly do this?

First of all, store all of your information in your database as it's
entered, and perform the regex and other string manipulation on the code
when you bring it out of the database.  That way, if you decide you could do
something better than you're currently doing later on, you have the "raw
data to deal with."

Anyway, now to your problem:



Hope it helps.

James



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




[PHP] Re: allowed tags reg exp

2002-04-10 Thread liljim

Hi

try this (untested)

 and friends with their html equivelants.
$input = htmlenitities($input);

$input = preg_replace("!<(b|i|u)>(.*?)!is", "<$1>$2",
$input);

echo $input;

?>


I use something like this on one of my sites, though I check as the user
inputs the info whether or not there are matching opening and closing tags
before inputting to the db, and later echoing them out and doing the
conversions...

Hope it helps, anyway.

~James

"Justin French" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hi all,
>
> Further to a discussion we had yesterday about the danger of onLoad,
> onMouseOver, etc etc of allowed tags when using strip_tags(), I've decided
> to look at the issue from another angle.
>
> For the limited set of tags I usually allow on user input, , I'm
> going take the approach of deleting anything I don't specifically TRUST,
> rather than deleting things I don't trust.
>
> For such simple tags, It seems to me to be a smarter move to delete
anything
> in the tag apart from the actual tag.
>
>  becomes 
>
> This eliminates the danger of people putting anything evil like
> onmouseover="javascript:self.close();" into my small set of allowed tags.
>
>
> So, I'd like a regexp which looks for multiple occurences of a tag (let's
> take  for an example), and throw out anything not needed.
>
> In English, I guess it looks like:
>
> look for a "<" followed by a "b" (case insensitive), then throw away
> anything up to the first ">" we find.
>
> Better still would be a regexp or function that checks for b|i|u, or a
> passed set of tags.
>
>
> I'm aware that this type of hard-line approach will prevent ,
> and I will also have problems on things like  and
 HREF="foo.php">, but I plan to devise some psuedo tags for links, and
don't
> require font tags, image tags, etc etc.
>
>
> Many thanks in advance,
>
> Justin French
>



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




[PHP] Re: formatting a numeric string

2002-04-10 Thread liljim

Hi Erik.

Try this:



~James

"Erik Price" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> I have the following code --
>
> $phone_number = "8005551212";
> $phone_array = explode("", $phone_number);
> $phone_number = sprintf("(%s%s%s) %s%s%s-%s%s%s%s", $phone_array[0],
> $phone_array[1], $phone_array[2], $phone_array[3], $phone_array[4],
> $phone_array[5], $phone_array[6], $phone_array[7], $phone_array[8]);
>
> Is this really the best way to achieve $phone_number = "(800)
> 555-1212" ?  Or am I taking the long way around, and there's a function
> that can do this better?
>
> Thanks,
>
>
> Erik
>
>
>
>
>
> 
>
> Erik Price
> Web Developer Temp
> Media Lab, H.H. Brown
> [EMAIL PROTECTED]
>



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




Re: [PHP] Re: syntax for checking if string contains something

2001-10-23 Thread liljim

Hey,

> if (isset($submit)){
> if (!empty($qty))
> {  echo "Please enter the quantity for your quotation enquiry.";}
>
>
> When nothing was filled in for $qty the if condition did not prompt me to
> enter a quantity.

This is wrong:

if (!empty($qty))
{  echo "Please enter the quantity for your quotation enquiry.";}

You're checking to see whether or not qty IS empty, this statement checks
for when when it is NOT empty

if (empty($string)) {
// This is an empty string.
}

if (!empty($string)) {
// This is NOT an empty string.
}


James



-- 
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] Re: mktime() problem

2001-10-23 Thread liljim

Hi James,

> I'm running 4.0.6 on a Solaris 8 box. The output given by
>
> echo mktime(0,0,0,1,1,1970);
>
> is 3600.
>
> Shouldn't it be 0? My box's locale is set to the UK defaults, so as I
write
> this we are in daylight savings (GMT+1). Would this make a difference? (I
> have already tried

I uploaded the same script to my server which is also running BST (GMT +1) :
the output was as I expected, -3600 (we gained an hour, so had to lose it
somewhere):  are you sure your value wasn't minus 3600 also?


James



-- 
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] Re: Regex problem

2001-10-25 Thread liljim

Hello Leon,

try this

if (preg_match("/^([[:space:]]*)?\*/s", $string)) {
 echo "Match.";
} else {
 echo "No match";
}

James

"Leon Mergen" <[EMAIL PROTECTED]> wrote in message
002f01c15d2a$e4ca3030$012aa8c0@leon">news:002f01c15d2a$e4ca3030$012aa8c0@leon...
Hi there,

I am camping with a little regular expressions problem...

Problem: I want to check if $variable begins with a * (star), and it doesn't
matter if it starts with plenty of spaces...

My solution:
ereg("^[:space:]*\*",$variable)

But, it doesn't seem to work with the space part... The regex:

ereg("^\*",$variable)

does work, but that doesn't include spaces at the start... How can I extend
this one so that it doesn't matter if there are a lot of spaces at the
begin?

Thanks in advance,

Leon Mergen




-- 
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] Re: regular expression

2001-11-01 Thread liljim

Hello,

"Galkov Vladimir" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Need to remove all "../"   "/.."  from user inputing string to prevent him
> walking and creating files&directories where I don't whant see them/him...
>
> The string:
>
>  $path =
> eregi_replace('([..]{2,})|([./]{2})|([../]{3,})|([/.]{2})|([/..]{3})', '',
> $path);
>
> works good with any  combinations ( ../../..qwert.txt  =>  qwert.txt)
untill
> somth like "/../asd/../qwert.txt" will be entered ...
(/../asd/../qwert.txt
> => asdqwert.txt).
>  So the qwestion is how upgrade regular expression to remove all this
> correctly (with all entered directory names but NOT assigned their names
to
> file name...
>
>  Must do the operation:
>  /../asd//qwert.txt  => qwert.txt
> but  not  => /asd/qwert.txt or asdqwert.txt.ru
> or
> /../asd/../qwert.txt.ru  => qwert.txt.ru
> but  not  => /asd/qwert.txt.ru or asdqwert.txt.ru
>

Try this:



May need some tweaking, let me know.

~James



-- 
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] Re: regular expression

2001-11-01 Thread liljim

Whooops,

Pasted wrong line.  This should do it:

$string = preg_replace("/(\.*\/)+(.*?\.*\/)?/s", "", $string);

James



-- 
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] Re: regular expression

2001-11-01 Thread liljim

> Whooops,
>
> Pasted wrong line.  This should do it:
>
> $string = preg_replace("/(\.*\/)+(.*?\.*\/)?/s", "", $string);

Gah... Not.. enough... caffeine: Modification:

$string = preg_replace("/(\.*\/)+(.*?\.*\/)?(\.*)?/s", "", $string);



-- 
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] Re: Need regular match help - possibly

2001-11-22 Thread liljim

Hello Gaylen,

try this:

$string = preg_replace("/\n{3,}/", "\n\n\n", $string);

James

"Gaylen Fraley" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> I need a routine that will allow me to trap multiple  and/or line feed
> characters and convert them to a constant number.  As an example, let's
say
> that you have text that has 10 carriage returns and/or line feeds.  I want
> to limit this to 3.  So, I need to be able to parse the line to detect the
> multiple control characters and convert the string to 3.  So if the string
> looked something like:
>
> This is \n\n\n\n\n\n\n\n\n\n a test.
>
> I would want it converted to
>
> This is \n\n\n a test.
>
>
> Conceivably, it could be
>
> This is  a test.
>
> I would want it converted to
>
> This is  a test.
>
>
> I know I could write a do/while loop, but I was wondering if there is a
way
> using eregi_replace or something along that line?
>
> Thanks!
>
>



-- 
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] Re: Need regular match help - possibly

2001-11-22 Thread liljim

Thinking about it, this would probably be even better:

$string = preg_replace("/(\n|){3,}/i", "\\1\\1\\1", $string);

This:
$string = "This is a
\n\n\n\n\n\n\n\n\n\n\ntest\nTesting\nTesting\n\n123<
br>Some more testingAnd
a little
more
Even more.";

Then outputs as this:

This is a 


test
Testing
Testing

123Some more testingAnd a little
moreEven more.

when echo'd with nl2br()

As a side note, does anyone know what's with the  tag changing to ?  That's the way I've always used the line break tag for wml pages, but
hadn't realised that it's being written that way for standard html now. Is
this a change in spec?

James

"Liljim" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hello Gaylen,
>
> try this:
>
> $string = preg_replace("/\n{3,}/", "\n\n\n", $string);
>
> James
>
> "Gaylen Fraley" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > I need a routine that will allow me to trap multiple  and/or line
feed
> > characters and convert them to a constant number.  As an example, let's
> say
> > that you have text that has 10 carriage returns and/or line feeds.  I
want
> > to limit this to 3.  So, I need to be able to parse the line to detect
the
> > multiple control characters and convert the string to 3.  So if the
string
> > looked something like:
> >
> > This is \n\n\n\n\n\n\n\n\n\n a test.
> >
> > I would want it converted to
> >
> > This is \n\n\n a test.
> >
> >
> > Conceivably, it could be
> >
> > This is  a test.
> >
> > I would want it converted to
> >
> > This is  a test.
> >
> >
> > I know I could write a do/while loop, but I was wondering if there is a
> way
> > using eregi_replace or something along that line?
> >
> > Thanks!
> >
> >
>
>



-- 
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] Re: about the replacing HTML code by another codes in a Forum ?

2001-11-22 Thread liljim

Hiya,

well, you could replace all script tags with this regex:

$string = preg_replace("/<\/?SCRIPT.*?>/is", "", $string);

But, if you're converting all < and > to their html equivelants (which you
should be) using something like htmlspecialchars or your own regex, you
shouldn't even need to do that.  You might also want to think about
strip_tags(), though again, I prefer just to convert the characters and not
worry about it.

as for your links, I'd rethink the user input and use something like
[a=www.microsoft.com]Click[/a] ;>

// quick and dirty regex
$string = preg_replace("/\[a=(.+?)\](.*?)\[\/a\]/is", "\\2", $string);

James

"Trongduc" <[EMAIL PROTECTED]> wrote in message
001101c17341$b6de6060$1d0b10ac@d">news:001101c17341$b6de6060$1d0b10ac@d...
> hi,
> can anyone help me this ?
>
> 1)
> I made a simple forum, and it will allow the users to send their messages
in
> HTML format.
> But I worried about the security of my website, so I removed all of the
> " (Because the users maybe use 

Re: [PHP] Reg ex help-Removing extra blank spaces before HTML output

2001-12-05 Thread liljim

Hello,

The example Jack gave you will clear up spaces well, though to get both
newlines and spaces into one:

$input = preg_replace("/([ ]|\n){1,}/", "\\1", $input);

James

"Jack Dempsey" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> $text = preg_replace('|\s+|',' ',$text);
>
>
> -Original Message-
> From: Ken [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, December 05, 2001 2:06 AM
> To: PHP list
> Subject: [PHP] Reg ex help-Removing extra blank spaces before HTML
> output
>
>
> I want to remove all superfluous blank spaces before I sent my HTML
output,
> to make the output smaller.
>
> So I'd like to take $input, replace any number of blank space or newlines
> that are consecutive and replace them with a single blank.
>
> I.e. I will list a blank space as b and a newline as n:
>
> If input is: bTEXTHEREbbbnnnbnMOREbEVENMORE
> Then output should be: bTEXTHEREbMOREbEVENMORE
>
> I imagine this would be handled by a simple regular expression call, but
I'm
> no pro with them yet.
>
> Any help?
>
> Thanks,
> Ken
> [EMAIL PROTECTED]
>
> --
> 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 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]