Jump to content


Photo

str_replace via a dropdown list


  • Please log in to reply
2 replies to this topic

#1 BlackKite

BlackKite
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 31 March 2006 - 01:49 AM

Hello! Ok this is sort of hard to explain but i'll do my best.

I've got a php site backend script im developing. A part of the script is a page uploader in which you give the file a title, the page a name, type in the content of the page, and then select from a drop down option list where on the sites navigation column you want the link to be displayed.

The problem is that I cant get navigation part to work correctly. I have it setup so that the script opens the index file, searches for a hidden html tag and then replaces the hidden tag with the link and a new hidden tag. In my eyes it looks like the hidden tag isn't being found and the scrip is just passing over that part becuase its not found.

Here are the parts of code that are connected to my problem. Any help at all would be appreciated greatly. Thanks!

Forms Drop List:
Navigation Spot:<br> <select name="navi">
<option value="nav1">1</option>
<option value="nav2">2</option>
<option value="nav3">3</option>
</select>


Php script that processes the this part of the form:
        //Post navigation link on index;

$nav = $_POST['navi'];

$SData = "<a href=\"index.php?id=$ourFileName\">$ourLinkName</a><br>

<!-- $nav -->";

$data = file_get_contents("$dir/index.php");

$data = str_replace ('<!-- $nav -->', $SData, $data);

$fp = fopen ("$dir/index.php", 'w');
fwrite ($fp, $data);
fclose ($fp);

Hidden tags on index.php page:
<!-- nav1 -->
<br>
<!-- nav2 -->
<br>
<!-- nav3 -->


#2 bqallover

bqallover
  • Members
  • PipPipPip
  • Advanced Member
  • 111 posts
  • LocationLeeds, UK

Posted 31 March 2006 - 02:30 AM

Hi. Not sure if I follow exactly what you're doing, but it looks to me like you're trying to expand the $nav variable in the str_replace. You'd need to wrap that in double-quotes, not single.

Instead of...
$data = str_replace ('<!-- $nav -->', $SData, $data);

you'd have...

$data = str_replace ("<!-- $nav -->", $SData, $data);

But as I say, I'm not really following the code that well. :)

#3 BlackKite

BlackKite
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 31 March 2006 - 02:37 AM

Wow, im stupid. How did i not think of trying that?!? It worked, lol. Thanks alot! :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users