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
https://forums.phpfreaks.com/topic/94031-get-data-from-2-files-into-array/
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);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.