need to do a string replace of "asc" to "desc" or "desc" to "asc" first occurrence only
- From: "comp.lang.php" <phillip.s.powell@xxxxxxxxx>
- Date: 3 Feb 2006 14:42:35 -0800
[PHP]
$orderBy = 's.app_date desc, s.last_name asc, s.first_name asc, s.mi
asc';
if ($_REQUEST['willDesc']) {
$ascArray = array('asc' => 'desc', 'desc' => 'asc'); // ARRAY OF
ALL ORDERING POSSIBILITIES
$junk = preg_match('/([\s\t]+)a|[de]sc(,?.*$)/i', $orderBy,
$matchArray);
$orderBy = substr($orderBy, 0, strpos($orderBy, $matchArray[1])) .
' ' . $ascArray[$matchArray[1]] .
substr($orderBy, strpos($orderBy, $matchArray[1]) +
strlen($matchArray[1]), strlen($orderBy));
}
[/PHP]
Basic premise:
I have a SQL "ORDER BY" clause that will be configured like $orderBy 's
value. However, the very first occurrence of "desc" might instead be
"asc". If the very first occurrence is "asc", it must become "desc";
likewise, if the very first occurrence is "desc", it must become "asc".
I tried Regular Expressions but the pattern failed every single time to
match and replace, so I gave up and tried a string function/RegExp code
combination, also to no avail.
I am not sure how to make this work so I need help figuring out how to
do this.
Thanx
Phil
.
- Follow-Ups:
- Prev by Date: PEAR::SOAP Class variable access problema
- Next by Date: Reading from file
- Previous by thread: PEAR::SOAP Class variable access problema
- Next by thread: Re: need to do a string replace of "asc" to "desc" or "desc" to "asc" first occurrence only
- Index(es):
Relevant Pages
|