NameSilo

Please help with me with Php!

Spaceship Spaceship
Watch

cesarian

Established Member
Impact
2
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>

You will see there %site_folders%.I need to replace %site_folders%.

content of folders.txt:
Code:
A
B

The output will be then:
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>

There are about more than 200 text that I need to replace please help me.

Thank you
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
I dont understand what you mean. I would help if i did!
 
0
•••
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.
 
0
•••
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:
<?php
$text = <<< END
<h2>title</h2>
<strong>some text here</strong>
   <img src="" alt="">
<p>some more text here.....</p>
END;
?>

and call it like:

PHP:
<table>
 <tr>
   <td><? echo $text; ?></td>
 </tr>
</table>

which will supply the following rendered source of:

PHP:
<table>
 <tr>
   <td>
<h2>title</h2>
<strong>some text here</strong>
   <img src="" alt="">
<p>some more text here.....</p>
</td>
 </tr>
</table>

I hope this helps you, if not please be more specific as to what you are trying to do.
 
0
•••
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:
<?php

$file = file('folders.txt');
foreach($file as $line) {
  echo the table stuff and $line is the line from the file..
}

?>
 
0
•••
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>

pageterms.txt
There are here about 200 lines text. Example of the file:
Code:
Hallo
This
Is
Line
2

I have created a php file that replace the text %menu_text% with the text from pageterms.txt. So the line is multiplied with the script and on each new line the %menu_text% is replaced. This is what I use:
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);
}

Now I will reaplaced the %site_folders from a text file but I can not use foreach like this:
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);
}

Can someone help me now? Thank you.
 
0
•••
Unstoppable Domains
Domain Recover
DomainEasy โ€” Live Options
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back