| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| NamePros Regular | Please help with me with php! Hi, I need some help with php. I want to replace multiple text with text from a folder. content that I need to replace: 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://%site_url%/images/bullet.jpg"></td><td width="1061"><a style="font-family: Verdana; font-size: 11px; text-decoration: none" href="http://%site_url%/%site_folders%/">60 Minute Money </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://%site_url%/images/bullet.jpg"></td><td width="1061"><a style="font-family: Verdana; font-size: 11px; text-decoration: none" href="http://%site_url%/%site_folders%/">7 Eleven Franchise </a></td></tr></table> content of folders.txt: Code: A B 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://%site_url%/images/bullet.jpg"></td><td width="1061"><a style="font-family: Verdana; font-size: 11px; text-decoration: none" href="http://%site_url%/A/">60 Minute Money </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://%site_url%/images/bullet.jpg"></td><td width="1061"><a style="font-family: Verdana; font-size: 11px; text-decoration: none" href="http://%site_url%/B/">7 Eleven Franchise </a></td></tr></table> Thank you |
| |
| | #3 (permalink) |
| Senior Member | your best bet would be to convert to using a template engine instead of tryin to write 1 yourself as effectively that is what you are doing. Also in your example there is no logical way to know which entry in folders.txt should be replacing which line in your original html.
__________________ Manage your portfolio using my new Domain Portfolio Management script. Securing Your Domain Name From Theft |
| |
| | #4 (permalink) |
| NamePros Member | Im not quite sure what you are talking about either, but I will give you a solution to using multiple lines, I hope it helps... You can use a here doc to achieve the following: PHP Code: PHP Code: PHP Code:
__________________ Complete Databases For Webmasters | Expired Domain Lists | Buy and Sell Domains | 29Net |
| |
| | #5 (permalink) |
| Buy my domains. | Hobnob, that doesn't make any sense at all any doesn't make anything dynamic. cesarian, I would help you, but I'm not sure where the things like '60 Minute Money' are coming from. The PHP would be something like: PHP Code: |
| |
| | #6 (permalink) |
| NamePros Regular | Hi, thank you for the reaply but they are not helping me. I tell you the original files. template_menu.txt There is actually only one line text here. 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://%site_url%/images/bullet.jpg"></td><td width="1061"><a style="font-family: Verdana; font-size: 11px; text-decoration: none" href="http://%site_url%/%site_folders%/">%menu_text%</a></td></tr></table> There are here about 200 lines text. Example of the file: Code: Hallo This Is Line 2 Code: <?php
$menu_template = file_get_contents("template_menu.txt");
$text_array = file("pageterms.txt");
foreach($text_array as $text) {
rows.=str_replace("%menu_text%",$text,$menu_template);
if (!fwrite($handle, $menu_template)) {
print "Can't write to file($menu_template)";
exit;
} else {
fwrite ($handel, $rows);
fclose ($handel);
}
Code: $menu_template = file_get_contents("template_menu.txt");
$text_array = file("pageterms.txt");
$sitefolders_aray = file("folders.txt");
foreach(foreach($text_array as $text, $sitefolders_array as $sitefolders) {
rows.=str_replace("%menu_text%",$text,$menu_template);
rows.=str_replace("%site_folders%",$sitefolders,$menu_template);
if (!fwrite($handle, $menu_template)) {
print "Can't write to file($menu_template)";
exit;
} else {
fwrite ($handel, $rows);
fclose ($handel);
}
|
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |