Jump to content

[SOLVED] Str replace, within a for statement?


spfoonnewb

Recommended Posts

I have this code, *again*, where it takes in a bunch of fields, url1, url2, url2, url4, url5, etc.. up to 999.. anyway I want it to replace http:// & www. in the string. In the code I add http:// & www. to make sure they didn't leave it out, and I replace it to make sure there isn't two of them. It fixes many problem possibilities. My question is how would I get this to work without losing the input from each value?

Here is my codes, they dont work due to .echo ["cat$l"].' but I tried other ways too. Please help :)

[code]<?php
$l = $_POST['i'];
for ($l = 1; $l <= $_POST['l']; ++$l)

$cat = str_replace("http://", "", $_POST["url$l"]);

$cat = str_replace("www.", "", $_POST["url$l"]);

{
  echo '<option value="http://www.'.echo ["cat$l"].'">'.$_POST["name$l"].'</option>';
}
?>[/code]
Is this what you're trying to do?
[code]
<?php
$l = $_POST['i'];
for ($l = 1; $l <= $_POST['l']; ++$l) {

$cat = str_replace("http://", "", $_POST["url$l"]);
$cat = str_replace("www.", "", $cat);

echo '<option value="http://www.' . $cat . '">' . $_POST["name$l"] . '</option>';
}
?>[/code]
Ok, thanks :)

It's basically just a precaution to make sure users don't forget the http://, cause links don't work without it

[code]<?php
$l = $_POST['i'];
for ($l = 1; $l <= $_POST['l']; ++$l) {

$cat = str_replace("http://", "", $_POST["url$l"]);
//$cat = str_replace("www.", "", $cat);

echo '<option value="http://' . $cat . '">' . $_POST["name$l"] . '</option>';
}
?>[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.