[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 05-10-2006, 01:50 AM   #1 (permalink)
NamePros Regular
 
Join Date: Mar 2006
Posts: 448
187.15 NP$ (Donate)

cesarian will become famous soon enoughcesarian will become famous soon enough

Save a Life Child Abuse Animal Rescue AIDS/HIV
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>
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
cesarian is offline  
Old 05-10-2006, 08:37 AM   #2 (permalink)
Senior Member
 
Xyzer's Avatar
 
Join Date: Aug 2005
Location: United Kindom
Posts: 1,506
90.70 NP$ (Donate)

Xyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to all

Tsunami Relief AIDS/HIV
I dont understand what you mean. I would help if i did!
Xyzer is offline  
Old 05-10-2006, 09:21 AM   #3 (permalink)
Senior Member
 
Peter's Avatar
 
Join Date: Nov 2003
Location: Scotland
Posts: 4,900
0.60 NP$ (Donate)

Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute

Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
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
Peter is offline  
Old 05-10-2006, 02:16 PM   #4 (permalink)
NamePros Member
 
Join Date: Mar 2006
Location: (US) Missouri
Posts: 43
0.00 NP$ (Donate)

Hobnob is an unknown quantity at this point


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
$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 Code:
<table>
<tr>
   <td><? echo $text; ?></td>
</tr>
</table>
which will supply the following rendered source of:

PHP Code:
<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.
Hobnob is offline  
Old 05-10-2006, 04:58 PM   #5 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
 
Join Date: Feb 2006
Posts: 2,801
56.00 NP$ (Donate)

Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future

Autism Autism Autism Autism Autism Autism Autism
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:
<?php

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

?>
Dan is offline  
Old 05-11-2006, 03:34 AM   #6 (permalink)
NamePros Regular
 
Join Date: Mar 2006
Posts: 448
187.15 NP$ (Donate)

cesarian will become famous soon enoughcesarian will become famous soon enough

Save a Life Child Abuse Animal Rescue AIDS/HIV
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.
cesarian is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 01:06 PM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85