Page 1 of 1

How to find a quote in a string

Posted: Thu Oct 23, 2008 3:10 pm
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>";



}


?>

Re: How to find a quote in a string

Posted: Thu Oct 23, 2008 4:04 pm
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) {