[Last Call] Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2009-12-27
Medium Priority
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
  • 4
  • 3
LVL 15

Expert Comment

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

Author Comment

ID: 26126699
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("http://dev.my.com/mod/my_theme/views/default/my1_pages/slogans.txt", "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

ID: 26126702
Its actually the apostrophe that is loading wired and the above lines of text show the problem. ^
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Author Comment

ID: 26126708
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

Insoftservice earned 700 total points
ID: 26126721
try this one.

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

Assisted Solution

Insoftservice earned 700 total points
ID: 26126758

Author Comment

ID: 26129122
ah - that works too :)

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month18 days, 6 hours left to enroll

830 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