Jump to content

Get data from 2 Files into array


imperialized

Recommended Posts

OK, here is my predicament. I have 2 .txt files with information directly correlating with each other. What I am trying to do is write an emoticons script for my news script. I have accomplished this in a very bulky way, I had to type everything out.

 

$replacednews = str_replace("", "<img src=\"emoticons/1.gif\" border=0>", $shortnews);  //  Face
$replacednews = str_replace("", "<img src=\"emoticons/10.gif\" border=0>", $replacednews);  //  Face
$replacednews = str_replace("", "<img src=\"emoticons/11.gif\" border=0>", $replacednews);  // Sweating Face Face
$replacednews = str_replace("", "<img src=\"emoticons/3.gif\" border=0>", $replacednews);  //  Sad Face
$replacednews = str_replace("", "<img src=\"emoticons/5.gif\" border=0>", $replacednews);  //  Grin Face
$replacednews = str_replace(":greensmoke:", "<img src=\"emoticons/cigarette.gif\" border=0>", $replacednews);  // Green smoking Face
$replacednews = str_replace(":smokechill:", "<img src=\"emoticons/smokin_chillen.gif\" border=0>", $replacednews);  //  smoking Face

However, in order to make it replace new smiles, I'd have to manually type in the code.

 

The text files contain the smilie text faces in one and the image that relates to which face in the other. Each entry is parallel to the one it relates to. ex: :) is on line 1 of the smilie.txt  and 1.gif is on line 1 of the other text file.

 

So my question is: How do I automate this process of replacing so that I can just edit the text files and it will do all this automatically.

Link to comment
Share on other sites

Chris92, your code wont work. file() returns the lines of the file being read into an array. So need to use explode.

 

<?php

$bbcode = file("code.txt", FILE_IGNORE_NEW_LINES);
$bbreplacements = file("replacments.txt", FILE_IGNORE_NEW_LINES);

$shortnews = str_replace($bbcode, $bbreplacements, $shortnews);

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.