loading text file with fopen - single and double quotes need to be encoded?

Posted on 2009-12-27
Last Modified: 2012-05-08
Hi I have simple text file that I am loading with fopen() but when I do the single and double quotes are change to odd looking characters. I recognize the problem as URL encoding but nothing seems to work. What am I missing?
Question by:waffe
    LVL 15

    Expert Comment

    can i see the text file and ur code. if possible.

    Author Comment

    Here you go:
    ****PHP code that loads the text file and converts each line into an element in an array and then displays a random line.*************
    	$file_handle = fopen("", "r") or die ("Unable to open file!");
    	$counter = 0;
    	while (!feof($file_handle)) {
    		$line_of_text = fgets($file_handle);
    		$sloganArray[$counter] = $line_of_text;
    	$randomNum = rand(1, 63);
    	print $sloganArray[$randomNum];
    ********the text I am opening***********
    Sometimes I feel like a nut, sometimes I feel like my1 
    Id walk a mile for my1 
    my1  99 99/100 % pure 
    With a name like my1&it has to be good 
    Is it live, or is it my1? 
    my1&so easy a caveman can do it. 
    I want my1 
    Nothing outlasts my1. It keeps going and going and going& 
    Like a good neighbor, my1 is there. 
    Maybe shes born with it, maybe its my1 
    Youve come a long way, my1 
    The my1 of champions 
    my1  good to the last video 
    my1&its GRE-A-A-A-T!! 
    Wouldnt you like to be my1, too? 
    I wish I were on my1, then everyone would be in love with me. 
    Nothing beats a great pair of my1s 
    The Greatest my1 on Earth 
    They my1 when you cook em. 
    I am stuck on my1, and my1s stuck on me! 
    my1  dont leave home without it 
    Its not your fathers my1 

    Open in new window


    Author Comment

    Its actually the apostrophe that is loading wired and the above lines of text show the problem. ^

    Author Comment

    ok got it - it was not an apostrophe, or at least one on my keyboard. so I selected and do a search & replace with a normal apostrophe and all is well.

    LVL 15

    Accepted Solution

    try this one.

     $line_of_text = preg_replace("/'/","&#146;",$file_handle);
    LVL 15

    Assisted Solution


    Author Comment

    ah - that works too :)

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    Introduction and Prerequisites This article describes methods for detecting whether a client browser accepts and returns HTTP cookies and whether the client browser runs JavaScript.  Most client browsers will, by default, be configured to use cooki…
    Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
    The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now