1st Post php and ¾ signs etc

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
langy01
Forum Newbie
Posts: 11
Joined: Wed Mar 11, 2009 6:15 am

1st Post php and ¾ signs etc

Post by langy01 »

Sorry I am not going to be able to give too many versions etc as its been a while since I set up my server.

I run Fedora Core 6 or 7 on a server and at the time of building it installed teh relevant php and mysql which has all been working fine and very reliable.

The initial database that I created opened htm pages and stripped out the required text to import in to the database. This all worked fine at the time and even now the data is displayed absolutely fine.

It has now come time to update the database with new records and amend some old ones. As I had over 2500 web pages to look at I created a script (AutoIT) that would open the required pages and save them to my PC. I then used some VBA in Excel to extract the information so that I could use that to compare and decide which records needed to be added and which needed to be amended and in some cases marked as deleted. The VBA then created a text file to create my own version of a csv file using the ^ as a delimiter as this is one character not used in any of the data.

All this has worked fine so far until I write my import program in php. Having said that just trying to get the ¾ to display in the php page is still an issue. So I have opened the file in php as a csv file max line size 1500 as lines can be up to about 1000 characters and used the ^ as a delimiter. The 39 fields all get read in to the array as expected each time. However if I display that data where there should be a ¾ or similar fractions and even £ they are not displayed.

Not sure what is causing this but I'm now looking at file types etc like unicode or ANSI but as I know nothing about these and probably barking up the wrong tree hopefully heres where someone comes along and points me in the right direction.

Oh and a simple php report can pull the existing data from the db and display the ¾ etc so its not db, server or the pc that has the issue so it has to be the code or file type.

Thanks for any help in advance.

Langy
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: 1st Post php and ¾ signs etc

Post by omniuni »

Try using htmlentities()

Does that help?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: 1st Post php and ¾ signs etc

Post by requinix »

langy01 wrote:However if I display that data where there should be a ¾ or similar fractions and even £ they are not displayed.
Not displayed or displayed wrong? There's a big difference.
langy01
Forum Newbie
Posts: 11
Joined: Wed Mar 11, 2009 6:15 am

Re: 1st Post php and ¾ signs etc

Post by langy01 »

Here is a snippet of data from a record imported a year or so ago.

½ac; views; Easter-Oct; £2.50;

That has the fractions and the pound sign.

With the data that I have read from a text file and imported in to the db the report shows it as below.

ac; quiet �8.50,

This has lost the fraction somewhere with either the reading or writing and the pound sign has now been replaced.

Below is a snippet of the SQL code to run the import created from the data and that is not being shown.

INSERT INTO ......... Desc='ac; quiet ......... �8.50,

If I use the &#190 then the fraction will show on the page, so I still suspect my problem is with reading the initial data.

Now I'm just delving in to my db and noticed that there is a À character before any fraction or £ sign, so this may well be the issue as these may have been stripped out of the text file before it was compiled.

I will investigate further.

However all comments gratefully received!
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: 1st Post php and ¾ signs etc

Post by omniuni »

I think that's because it's stored in some less-standard ascii format. Try htmlentities, but you may have to do something more tricky if those characters were not entered originally by code.
langy01
Forum Newbie
Posts: 11
Joined: Wed Mar 11, 2009 6:15 am

Re: 1st Post php and ¾ signs etc

Post by langy01 »

Not actualy used htmlentities before.

Is there certain way then that I should be treating the characters when I write then to a text file using VBA?
Messing around with the vba side may be easier for me to deal with and would certainly make life easier in the future.

The whole point of me getting everything in to Excel to start with was so that I could deal with the new and old data to start with and then produce a suitable export from Excel straight in to some php code to go in to the database.

Langy
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: 1st Post php and ¾ signs etc

Post by omniuni »

make sure you're using some standard encoding on your CSV's, not the Excel-standard windows encoding.... utf-8 I think (someone correct me if I'm wrong). If you're having trouble with Excel's text files, try using OpenOffice.org Calc. It's nearly as powerful, can open excel files, and it should produce CSV's that will be easier for PHP to deal with. You need to convert your special characters to htmlentities to make sure that the browser knows how to display them. For example, if I want to display the pound sign, if you run it through htmlentities, PHP will convert it to £ which will display reliably.
langy01
Forum Newbie
Posts: 11
Joined: Wed Mar 11, 2009 6:15 am

Re: 1st Post php and ¾ signs etc

Post by langy01 »

Update!

Right I think that I have sussed most of the issues now, the fields within the csv file have all been wrapped in "".
All of teh fractions are showing perfectly.

Just a minor issue now is that with the £ sign there is allways a trailing space that follows it.
Its a bit annoying as the existing data does not have this.

Any ideas welcomed, but I will have a play around.

Langy
langy01
Forum Newbie
Posts: 11
Joined: Wed Mar 11, 2009 6:15 am

Re: 1st Post php and ¾ signs etc

Post by langy01 »

Sorry wrong data used and it didn't work exacty as planned.

With wrapping the fields with the double quotes it imports the proper fractions and £ signs exactly as they should be in to the database. So the old records and the new look within the database exactly as they should.

Its only when you run the reports to view the contents through php that you get � for every fraction and £ sign.

Strange how all of the data new and old looks exactly correct from within the MySQL Query Browser but php shows it differently.

Oh well I'll play more.

Langy
langy01
Forum Newbie
Posts: 11
Joined: Wed Mar 11, 2009 6:15 am

Re: 1st Post php and ¾ signs etc

Post by langy01 »

omniuni wrote:make sure you're using some standard encoding on your CSV's, not the Excel-standard windows encoding.... utf-8 I think (someone correct me if I'm wrong). If you're having trouble with Excel's text files, try using OpenOffice.org Calc. It's nearly as powerful, can open excel files, and it should produce CSV's that will be easier for PHP to deal with. You need to convert your special characters to htmlentities to make sure that the browser knows how to display them. For example, if I want to display the pound sign, if you run it through htmlentities, PHP will convert it to £ which will display reliably.
RESULT!!!!!

Many Thanks omniuni!!!

I opened the text file with notepad and then did a saveas using the UTF-8 format.
Everything imports exactly as it should do. Guess that must be the format of an html file aswell then.

Many thanks to everyone who has helped.

Langy
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: 1st Post php and ¾ signs etc

Post by omniuni »

:D

You're welcome!
Post Reply