Forum Moderators: coopster
$b = "topic-".<$number-variable>."html";
$a = str_replace($b, "topic_".<$number-variable>."php", $string);
echo $a;
I would like to know what the "<$number-variable>" <---- would be?
so if/when $string contains in this case: topic-23423.html (23423 is hypothetical) it will convert it over to: topic_23423.php. however the number string will change periodically, and I need php to expect a number range? whats the php code for <$number-variable> in this case?
I need php to expect a number range? whats the php code for <$number-variable> in this case?
Like this?
if ($number_variable > 0) {
$b = "topic-".$number_variable."html";
$a = str_replace($b, "topic_".$number_variable."php", $string);
}
Unless you expect to have a file topic_0.html, use > 0 rather than is_numeric().
If you're doing what I **think** you're doing, Consider,
$request = 'example.com/products/12345'; // Etc., the page request
$full_page = '/server/path/to/directory';
$dir = '/products'; // Or use explode below to parse
$vars = explode('/',$request);
$number_variable = array_pop($vars); // Last item in array
if ($number_variable > 0) {
$page = 'topic_' . $number_variable . '.php';
if (is_file("$full_path/$page")) {
header("Location:$dir/$page");
}
else { "echo invalid file request"; exit; }
}
else { echo "Invalid page request"; }