PHP - strlen help

Associate
Joined
13 Nov 2003
Posts
1,567
Location
Manchester
Hi All

Just working on a quick script to generate the URL rewrite file for a site.

I need to use strlen in an 'if else' statement for part of it and I cant get it to work.

This is the code

Code:
$file= fopen("rewrite_rules.txt", "w");
$_xml = 'rewrite file category rules\r\n;';

// Select all categories //
mssql_select_db('***', $conn);
$sql = "SELECT * FROM categories where hideshow = '1'";
$result = mssql_query($sql);
while($row = mssql_fetch_array($result)){
if (strlen($row['id']) == 2) {
$_xml .="RewriteRule /".$row['urlrewrite']." /display_products.asp?id=".$row['id']." [I,L]\r\n";}

else {
$_xml .="RewriteRule /".$row['urlrewrite']." /browse_category.asp?id=".$row['id']." [I,L]\r\n";}
}
fwrite($file, $_xml);
fclose($file);
echo "Rewrite rules written";

I have tried all sorts. I need to run the first chunk of code for the when there are two characters in the ID and the second chunk when there is one.

Thanks in advance

Aaron
 
Oops, basically it only ever processes the top bit of code, regardless of how long the string is

Thanks
Aaron
 
do a var_dump($row['id']); to get a full understanding of exactly what is being returned.. it may be that it has some whitespace (which counts as length)
 
Yeah its white space :(

Whats? the best way to resolve that.

Shall I just use a replace to get rid of it

Aaron
 
Back
Top Bottom