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]
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.