How to find a quote in a string

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
kjmcsd
Forum Newbie
Posts: 1
Joined: Thu Oct 23, 2008 3:09 pm

How to find a quote in a string

Post by kjmcsd »

I have a text file. My text file contains lines with double quotes
around it. I trying to code if a line has double quotes around it Then
make it bold

My code is below and it is not working. Please Help
<?


$filename = "whatsnew.txt"; # file to read


if (file_exists($filename)) {


# Get a handle to the asdfile
$file = file($filename);


echo "<p style='font-family:Arial; font-size:x-small'>";


foreach($file as $line) {
if (strpos($line,"\"") > 0) {


$line = "<b>" . $line . "</b>";
}
$line .= "<br />";
echo $line;
}
echo "</p>";



}


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

Re: How to find a quote in a string

Post by requinix »

Code: Select all

if (strpos($line,"\"") > 0) {
If the " is the first character on the line, strpos will return 0. And 0>0 is false.

Code: Select all

if (strpos($line, "\"") !== false) {
Post Reply