Jump to content

Archived

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

BlackKite

str_replace via a dropdown list

Recommended Posts

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:
[code]Navigation Spot:<br> <select name="navi">
<option value="nav1">1</option>
<option value="nav2">2</option>
<option value="nav3">3</option>
</select>[/code]

Php script that processes the this part of the form:
[code]        //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);
[/code]

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

Share this post


Link to post
Share on other sites
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...
[code]
$data = str_replace ('<!-- $nav -->', $SData, $data);
[/code]

you'd have...

[code]
$data = str_replace ("<!-- $nav -->", $SData, $data);
[/code]

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

Share this post


Link to post
Share on other sites

×

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.