![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
Join Date: Sep 2006
Posts: 4,325
|
PHP Coders
Was wondering how to code something like this.. or if there was a script that does this. Php or otherwise.
I want to take a bit of text with variables in it, duplicate it 50 times, and replace each variable with certain text that I have line by line in text files. Anyone? ![]()
__________________
[email protected] |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
Confirmed User
Join Date: Apr 2006
Posts: 682
|
It's 4am and I haven't gone to bed yet, so I'm not going to be super helpful... but you could just store the strings you're wanting to use in an array and then either randomly or in order substitute into your "bit of text."
I do something kinda like that on some pages for an ad rotator. There is a php include that calls a separate file that I have different banners/ad-copy.. it just displays them randomly so surfers don't keep seeing the same one. I didn't want to bother creating a database for something so simple.. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
Confirmed User
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,229
|
str_replace();
__________________
Mechanical Bunny Media Mechbunny Tube Script | Mechbunny Webcam Aggregator Script | Custom Web Development |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
Confirmed User
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,229
|
err nm sorry im drunka nd didn't read entire post.
First off you wanna do file_get_contents() to read the textfile in, Then explode(); on \n's then foreach($array as $i) { $var = str_replace('variable',$i,$originalstring); }
__________________
Mechanical Bunny Media Mechbunny Tube Script | Mechbunny Webcam Aggregator Script | Custom Web Development |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
Confirmed User
Join Date: Apr 2006
Posts: 682
|
That's pretty good for being drunk.
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
Confirmed User
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,229
|
what can i say, im talented :P
__________________
Mechanical Bunny Media Mechbunny Tube Script | Mechbunny Webcam Aggregator Script | Custom Web Development |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 | |
Confirmed User
Industry Role:
Join Date: Mar 2004
Location: Rock Hill, SC
Posts: 5,370
|
Quote:
if you have to files that are exactly the same length in lines then you just have to read them both in... iterate the arrays... make your replacements and output the result. Code:
$file1 = file('path_to_first_file'); $file2 = file('path_to_second_file'); //assuming that this file contains delimited text for the purpose of this example $line_iterator = 0; foreach ($file1 as $line) { if (!empy($line)) { list($var1, $var2, $var3) = explode(',', $file2[$line_iterator]); //pull variable from corresponding line of file #2 that are comma delimited $temp_line = str_replace('<{var1}>', $var1, $line); $temp_line = str_replace('<{var2}>', $var2, $temp_line); $temp_line = str_replace('<{var3}>', $var3, $temp_line); $output .= $temp_line; //add the line to the output unset($temp_line); } $line_iterator++; } echo $output; |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 |
Confirmed User
Industry Role:
Join Date: Mar 2004
Location: Rock Hill, SC
Posts: 5,370
|
Code:
if (!empy($line)) { Code:
if (!empty($line)) { |
![]() |
![]() ![]() ![]() ![]() ![]() |