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.

Post New Thread Reply

Register GFY Rules Calendar Mark Forums Read
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 03-04-2007, 02:58 AM   #1
donkevlar
Confirmed User
 
donkevlar's Avatar
 
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]
donkevlar is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-04-2007, 03:24 AM   #2
ungratefulninja
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..
ungratefulninja is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-04-2007, 03:37 AM   #3
k0nr4d
Confirmed User
 
k0nr4d's Avatar
 
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,229
str_replace();
k0nr4d is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-04-2007, 03:40 AM   #4
k0nr4d
Confirmed User
 
k0nr4d's Avatar
 
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); }
k0nr4d is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-04-2007, 04:01 AM   #5
ungratefulninja
Confirmed User
 
Join Date: Apr 2006
Posts: 682
That's pretty good for being drunk.
ungratefulninja is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-04-2007, 04:40 AM   #6
k0nr4d
Confirmed User
 
k0nr4d's Avatar
 
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,229
what can i say, im talented :P
k0nr4d is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-04-2007, 05:56 AM   #7
nation-x
Confirmed User
 
nation-x's Avatar
 
Industry Role:
Join Date: Mar 2004
Location: Rock Hill, SC
Posts: 5,370
Quote:
Originally Posted by k0nr4d View Post
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); }
PHP has a built in function for that http://www.php.net/file that reads the file and puts each line of the file into an array element.

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;

Last edited by nation-x; 03-04-2007 at 05:57 AM..
nation-x is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-04-2007, 06:02 AM   #8
nation-x
Confirmed User
 
nation-x's Avatar
 
Industry Role:
Join Date: Mar 2004
Location: Rock Hill, SC
Posts: 5,370
Code:
if (!empy($line)) {
This needs to be

Code:
if (!empty($line)) {
nation-x is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks
Thread Tools



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.