Re: [PHP] need to change $ char in string

2002-06-29 Thread Uli B

use single quotes: double quotes would confuse php with variable names.
it thinks that $General is a variable and replace it by it's empty content.
single quotes prevent php from evaluating the string:

$test_string = '1.2$General/ms1.zip'; 

single quotes on regex too (same reason). the backslash in this case
(\$) refers to perl regular expression syntax but does not take care of php !

$new_string = preg_replace('/\$/', "%", $test_string); 

ub


At 10:58 29.06.02 -0400, Beverly Steiner wrote:
>I've tried everything I can think of to change a dallar sign in a string to
>something else or to split the string on the $ but I can't the the
>information that comes after the $.
>
>Typical string contains: 1.2$General/ms1.zip
>
>when I try:
>   $new_string = preg_replace("/\$/", "%", $test_string);
>
>or (trying to avoid specifying the $):
>   $new_string = preg_replace("/(\d\.\d{1,2})\D(\w.*$)/", "\1%\2",
>$test_string);
>
>echo "new_string is $new_string"; prints new_string is 1.2
>
>Has anyone solved this problem?
>
>Thanx,
>
>Bev
>
>
>-- 
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php

-- 
---
 Ulrich Borchers
 Brandenberger Straße 18, 41065 Mönchengladbach
 fon +49-2161-175883
 icq 1282868
---


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




RE: [PHP] need to change $ char in string

2002-07-01 Thread Uli B

(After typing I see that the problem is solved. I send it anyway -
hope you people don't mind the redundancy :-)


Why don't you use explode() again on the $ like Jason suggested ? 
This does not even require single quotes :-)
You might also want to have a look at split() and preg_split().

It should make no difference that the data comes from a database.
The $ probably requires no quoting (\) then. So I don't think this will help 
but you might try to apply quotemeta() before splitting or replacing.

I suggest that you take a close look at the data in you old database.
Are there any additional special characters that might ruin the effort ? 
The preg_* functions can make use of pattern modifiers that 
change the way these functions handle newlines for example
(see regular expressions).

If all of the above does not help you can have MySQL handle it:

select replace(str,'$','%') from table

...but that is not a preferable option imho because there seems to
be a problem elsewhere.

Uli


At 10:47 01.07.02 -0400, Beverly Steiner wrote:
>Uli & others,
>
>Thanx for the suggestions.  This works as stated but the data already exists
>in this format from an old database and I'm trying to parse it into logical
>fields.  Originally the data in the field looked something like
>1$General/ms1.zip#12$Another/xqy.zip#.  I deleted the ending # then used
>explode to separate the information on the # and now I need to separate the
>info before the $ from what comes after it.  I've tried everyone's
>suggestions but they only work if I'm testing and can define the string
>using single quotes.
>
>How can I split on a $ or change the $ to something else if I'm getting the
>information from a database (MySQL), not defining it using single quotes
>like in your example?
>
>Bev
>
>
>-Original Message-
>From: Uli B [mailto:[EMAIL PROTECTED]]
>Sent: Saturday, June 29, 2002 11:56 AM
>To: PHP List
>Subject: Re: [PHP] need to change $ char in string
>
>
>use single quotes: double quotes would confuse php with variable names.
>it thinks that $General is a variable and replace it by it's empty content.
>single quotes prevent php from evaluating the string:
>
>$test_string = '1.2$General/ms1.zip';
>
>single quotes on regex too (same reason). the backslash in this case
>(\$) refers to perl regular expression syntax but does not take care of php
>!
>
>$new_string = preg_replace('/\$/', "%", $test_string);
>
>ub
>
>
>At 10:58 29.06.02 -0400, Beverly Steiner wrote:
>>I've tried everything I can think of to change a dallar sign in a string to
>>something else or to split the string on the $ but I can't the the
>>information that comes after the $.
>>
>>Typical string contains: 1.2$General/ms1.zip
>>
>>when I try:
>>  $new_string = preg_replace("/\$/", "%", $test_string);
>>
>>or (trying to avoid specifying the $):
>>  $new_string = preg_replace("/(\d\.\d{1,2})\D(\w.*$)/", "\1%\2",
>>$test_string);
>>
>>echo "new_string is $new_string"; prints new_string is 1.2
>>
>>Has anyone solved this problem?
>>
>>Thanx,
>>
>>Bev
>>
>>
>>--
>>PHP General Mailing List (http://www.php.net/)
>>To unsubscribe, visit: http://www.php.net/unsub.php
>
>--
>---
> Ulrich Borchers
> Brandenberger Straße 18, 41065 Mönchengladbach
> fon +49-2161-175883
> icq 1282868
>---
>
>
>--
>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




Re: [PHP] Re: checking

2002-07-01 Thread Uli B

"==" (2) is for comparison while you are accidently doing assignments by
"=" (1)
if ($lastname="") - wrong
if ($lastname=="") - better
that's why u r screwed up here :-)

Uli

At 17:49 30.06.02 -0500, Richard Lynch wrote:
>In article <03d201c21db6$7deb2110$7800a8c0@leonard> , [EMAIL PROTECTED]
>(Leo) wrote:
>
>>I have a form and I don't want to insert recording with blank value.
>>I put:
>>if ($lastname="") {
>>$insert="no"
>>}
>>if ($insert="no"){
>>do not insert;
>>else
>>insert;
>>}
>>my probleme is in some case $lastname="" is true and other case is false.
>>I tried with $lastname=" " but no change. how can I check if a varible is
>>empty or not?
>
>
>if (isset($lastname)){
>  # Do MySQL insert
>}
>
>http://php.net/isset
>
>NOTE:
>CHECKBOX variables will not show up unless checked, so this technique will
>not necessarily work for them, depending on what business logic you are
>trying to achieve...
>
>-- 
>Like Music?  http://l-i-e.com/artists.htm
>
>
>-- 
>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] Regular Expression Problem

2002-07-02 Thread Uli B


- don't use /^ .. $/ if you want to replace all occurences.  ^ and $ refer
to the very start and end of the whole string
  and make no sense at all - at least in this case. your regexp will not
match at all unless $var contains only a 
  single variable and nothing more
- either capture (something) by brackets, otherwise use \\0 instead of \\1
- you forgot the "&" : try  [\$\&]?\$
- [a-zA-Z][0-9]+  most variable names will not match this expr except
things like $a089666. do you name all of your
  variables like this ?!  [a-zA-Z_][\w\d\_]* is a good approach I guess but
some more characters are valid (RTFM:
  "Variables - BASICS")
- "$" is no good here as stated below

uli

At 02:30 03.07.02 +0800, you wrote:
>On Wednesday 03 July 2002 01:59, Martin Clifford wrote:
>> Even this:
>>
>> $output = preg_replace("/^[\$]{1,2}[a-zA-Z][0-9]+$/", "\\1", $var);
>> echo $output;
>>
>> Doesn't work.  It just takes whatever you put into $var, then puts it into
>> $output, and outputs it to the screen.
>>
>> I want to change anything resembling a PHP variable, i.e. $var, $$var or
>> &$var to $var.  Any ideas on how to do that?
>
>Don't use "" strings unless you need variable expansion.
>
>Try:
>
>'/^\${1,2}[ 
>
>
>... actually try RTFM, the section on variables gives you a regex definition 
>of acceptable PHP variables!
>
>-- 
>Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
>Open Source Software Systems Integrators
>* Web Design & Hosting * Internet & Intranet Applications Development *
>
>/*
>To be sure of hitting the target, shoot first and, whatever you hit,
>call it the target.
>*/
>
>
>-- 
>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