Unstoppable Domains

Please help me with PHP!

Spaceship Spaceship
Watch

cesarian

Established Member
Impact
2
Hi, I need some help with php. I have a file index.html. I want to replace the links of the index.html, so I write:
Code:
<body>
%menu%
</body>
Then I have menu_template.txt:
Code:
<table id="AutoNumber1" style="border-collapse: collapse; font-family: Verdana; font-size: 11px; text-decoration: none" borderColor="#111111" cellSpacing="0" cellPadding="3" width="100%" border="0"><tr><td width="19"><img src="http://mysite.com/images/bullet.jpg"></td><td width="1061"><a style="font-family: Verdana; font-size: 11px; text-decoration: none" href="http://mysite.com/folders/">%text_menu%</a></td></tr></table>

I also have terms.txt:
Code:
A
B
C

I want to replace %menu% in index.html file with text in menu_template.txt. In menu_template.txt I want to multiple the text and replace %text_menu% with the terms from terms.txt.

The output will be like this:
Code:
<body>
<table id="AutoNumber1" style="border-collapse: collapse; font-family: Verdana; font-size: 11px; text-decoration: none" borderColor="#111111" cellSpacing="0" cellPadding="3" width="100%" border="0"><tr><td width="19"><img src="http://mysite.com/images/bullet.jpg"></td><td width="1061"><a style="font-family: Verdana; font-size: 11px; text-decoration: none" href="http://mysite.com/folders/">A</a></td></tr></table>
<table id="AutoNumber1" style="border-collapse: collapse; font-family: Verdana; font-size: 11px; text-decoration: none" borderColor="#111111" cellSpacing="0" cellPadding="3" width="100%" border="0"><tr><td width="19"><img src="http://mysite.com/images/bullet.jpg"></td><td width="1061"><a style="font-family: Verdana; font-size: 11px; text-decoration: none" href="http://mysite.com/folders/">B</a></td></tr></table>
<table id="AutoNumber1" style="border-collapse: collapse; font-family: Verdana; font-size: 11px; text-decoration: none" borderColor="#111111" cellSpacing="0" cellPadding="3" width="100%" border="0"><tr><td width="19"><img src="http://mysite.com/images/bullet.jpg"></td><td width="1061"><a style="font-family: Verdana; font-size: 11px; text-decoration: none" href="http://mysite.com/folders/">C</a></td></tr></table></body>

Would someone please help me? Please PM me or replay this post. Thank you.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
0
•••
PHP:
<?php
$page_template=file_get_contents("index.html");
$row_template=file_get_contents("menu_template.txt");
$term_array=file("terms.txt"); //forgot a quote, thanks jim

foreach($term_array as $term){
     $rows.=str_replace("%text_menu%",$term,$row_template);
}

echo str_replace("%menu%",$rows,$page_template);

?>

This should work. I haven't tested it, and just wrote it now into this textbox, but it should work. If you need an explanation of why or how it works, PM me.
 
Last edited:
0
•••
PHP:
$term_array=file("terms.txt");
You forgot a quote ;)
 
0
•••
Thank you for the code but I do not really understand the first code(I am a beginner) and the second code did not work.

The problem is that I want to replace %menu% but it won't replace it and what I need now is not only to replace %text menu% but also the url folders. So I have now also folders.txt.

The script must then count the line in terms.txt and multiple the line in menu_template.txt and replace %text_menu% and %folders%.

Output example:
Code:
<body>
<table id="AutoNumber1" style="border-collapse: collapse; font-family: Verdana; font-size: 11px; text-decoration: none" borderColor="#111111" cellSpacing="0" cellPadding="3" width="100%" border="0"><tr><td width="19"><img src="http://mysite.com/images/bullet.jpg"></td><td width="1061"><a style="font-family: Verdana; font-size: 11px; text-decoration: none" href="http://mysite.com/hallo/">A</a></td></tr></table>
<table id="AutoNumber1" style="border-collapse: collapse; font-family: Verdana; font-size: 11px; text-decoration: none" borderColor="#111111" cellSpacing="0" cellPadding="3" width="100%" border="0"><tr><td width="19"><img src="http://mysite.com/images/bullet.jpg"></td><td width="1061"><a style="font-family: Verdana; font-size: 11px; text-decoration: none" href="http://mysite.com/my/">B</a></td></tr></table>
<table id="AutoNumber1" style="border-collapse: collapse; font-family: Verdana; font-size: 11px; text-decoration: none" borderColor="#111111" cellSpacing="0" cellPadding="3" width="100%" border="0"><tr><td width="19"><img src="http://mysite.com/images/bullet.jpg"></td><td width="1061"><a style="font-family: Verdana; font-size: 11px; text-decoration: none" href="http://mysite.com/world/">C</a></td></tr></table></body>

You will see that the %text menu% is now A, B and C and the folders are Hallo, My and World. Please help me.

Thank you
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Unstoppable Domains
Domain Recover
DomainEasy โ€” Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back