HighDots Forums  

PHP String Replace Question

Macromedia Dreamweaver Macromedia Dreamweaver Discussions (macromedia.dreamweaver)


Discuss PHP String Replace Question in the Macromedia Dreamweaver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
David B
 
Posts: n/a

Default PHP String Replace Question - 07-24-2004 , 04:51 AM






The script below works fine for most codes, but I can only use the last
two letters of hyphenated codes, such as these:

us-ak, ca-ab

In other words, I need to strip us- and ca- out of $mycode. I have
another script that does just that, but I haven't been able to adapt it
to this one. can someone show me how to write it?

Thanks.

PHP Code:
<?php
$result 
mysql_query('select count(*) from gatesstatesart');
if ((
$result) && (mysql_result ($result 0) > 0)) {
// continue here with the code that starts
//$res = mysql_query ("SELECT * FROM type.....
} else {
die(
'Invalid query: ' mysql_error());
}
{
$res mysql_query ("SELECT * FROM gatesstatesart
WHERE IDArea = '$mycode'"
) or die (mysql_error());
while (
$row mysql_fetch_array ($res))

if (
$row['GNArt'])
echo 
$row['GNArt'];
else
include (
$_SERVER['DOCUMENT_ROOT']."/includes/const.php");
}
?>

Reply With Quote
  #2  
Old   
Jason Dalgarno
 
Posts: n/a

Default Re: PHP String Replace Question - 07-24-2004 , 05:57 AM






David B <david_blomstromDELETETHIS (AT) yahoo (DOT) com> wrote in
news:cdt7us$nk1$1 (AT) forums (DOT) macromedia.com:

Quote:
if (($result) && (mysql_result ($result , 0) > 0)) {
// continue here with the code that starts
//$res = mysql_query ("SELECT * FROM type.....
} else {
die('Invalid query: ' . mysql_error());
}
Zero matching rows is not an invalid query.

$mycode = preg_replace('/^[a-z]{2}-/', '', $mycode);

http://www.php.net/preg_replace
http://www.php.net/pcre.pattern.syntax


Reply With Quote
  #3  
Old   
Michael Fesser
 
Posts: n/a

Default Re: PHP String Replace Question - 07-24-2004 , 10:16 AM



.oO(David B)

Quote:
The script below works fine for most codes, but I can only use the last
two letters of hyphenated codes, such as these:

us-ak, ca-ab

In other words, I need to strip us- and ca- out of $mycode.
substr($mycode, -2)

returns the last two chars.

Quote:
I have
another script that does just that, but I haven't been able to adapt it
to this one. can someone show me how to write it?

[...]
$res = mysql_query ("SELECT * FROM gatesstatesart
WHERE IDArea = '$mycode'") or die (mysql_error());
$res = mysql_query('SELECT ... FROM gatesstatesart
WHERE IDArea = "'.substr($mycode, -2).'"') or ...

Micha


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.