Northern Rock | Credit Cards | Get out of Debt | Secured Loans | Free Advertising
Replacing chars in PHP [Archive] - PCMech Forums

PDA

View Full Version : Replacing chars in PHP


rcx21000
04-13-2004, 07:08 AM
I have a textfile thats made like this:

thing description
thing description
thing description
...

I can read it, and seperate "thing" and "description", if they are both one word, but they need to be lots of words. The only way that I can think to fix it would be replace all the " " with "|", except the ones that seperate "thing" and "description". Is there a way in PHP to replace all "|" with " " after I've seperated "thing" and "description? If you don't get me, then what I need is a function that will work something like "replace" in VB:

Replace("This|is|a|string|thing.", "|", " ") will give "This is a string thing"

I've googled it, and can't find the answer, either :(

aym
04-13-2004, 07:17 AM
Yes, there is a similar function in PHP, str_replace (http://www.php.net/str_replace).

However,if you can explain more what you are trying to do, I think there is a better way to do it.

rcx21000
04-13-2004, 08:54 AM
I want to make a site with GP32 (a korean handheld game thingy) downloads. "Thing" would be the path (like games\gloop.fxe) and "Description" would be a description of the download.

Databases seem to complicated for me :(

aym
04-13-2004, 04:48 PM
I'm afraid you'll run into much more trouble trying to store data in flat files, you'll need to write your own read/write functions, handle concurrency, and flat files become slow when they have a lot of data.

Make your life easier and use a database, I suggest you start learning them, and if you find something difficult to understand, you can always ask here :)

EDIT:

MySQL tutorials:
http://www.onlamp.com/pub/a/php/2003/12/23/php_foundations.html
http://www.onlamp.com/pub/a/php/2004/01/09/php_foundations.html
http://www.onlamp.com/pub/a/php/2004/01/29/php_foundations.html

Using MySQL with PHP tutorial:
http://www.onlamp.com/pub/a/php/2004/02/19/php_foundations.html