-1

Here's a copy of my current code:

  echo '<td style="word-wrap: break-word;">
     <div><center><a style="text-decoration:none;color:#489FDC;" href="http://local.mysite.com/'.echo basename(__DIR__);.'/'.strtolower(str_replace(" ","-",$row[cities])).'">'.ucwords($row[cities]).'</a></center></div>
   </td>'; 

But I am getting this error and can't figure out how to fix it:

[21-Feb-2014 11:46:08 America/Chicago] PHP Parse error:  syntax error, unexpected T_ECHO in /home/username/public_html/local/advertising-company/index.php on line 196

I know it has something to do with this part of the code:

'.echo basename(__DIR__);.'

What do I need to change to fix this?

user3286482
  • 161
  • 2
  • 3
  • 9
  • 1
    Just leave out the second `echo` - `"abc".basename(__DIR__)."def"` is what you should do. – davidkonrad Feb 21 '14 at 17:50
  • 1
    That's inceptionous thinking, sir. – Sterling Archer Feb 21 '14 at 17:52
  • Write a PHP function to format your data instead of slapping a glob of PHP inside your HTML. If you ever need to do maintenance on such an obfuscated code, you will waste time trying to figure out what it actually does and probably end up rewriting it from scratch. – kuroi neko Feb 21 '14 at 17:59
  • possible duplicate of [PHP: Using a variable inside a double quotes](http://stackoverflow.com/questions/10512452/php-using-a-variable-inside-a-double-quotes) –  Feb 21 '14 at 18:06
  • This is essentially a duplicate... But only isn't because the OP doesn't know what he's saying. The answer is in that questions answer (http://stackoverflow.com/a/10512466/1596138) –  Feb 21 '14 at 18:07

8 Answers8

1

Remove the other one,

echo '<td style="word-wrap: break-word;">
      <div><center><a style="text-decoration:none;color:#489FDC;" 
      href="http://local.mysite.com/'.basename(__DIR__).
      '/'.strtolower(str_replace(" ","-",$row[cities])).'">'.
      ucwords($row[cities]).'</a></center></div>
      </td>'; 
Rikesh
  • 26,156
  • 14
  • 79
  • 87
1
  1. Remove second echo
  2. Use quotes for array elements: $row[cities] should be $row['cities']
Mike
  • 1,158
  • 5
  • 22
  • 32
0

You dont need to do echo inside echo you can do as

echo '<td style="word-wrap: break-word;">
     <div><center><a style="text-decoration:none;color:#489FDC;" href="http://local.mysite.com/'.basename(__DIR__).'/'.strtolower(str_replace(" ","-",$row[cities])).'">'.ucwords($row[cities]).'</a></center></div>
   </td>'; 
Abhik Chakraborty
  • 44,654
  • 6
  • 52
  • 63
  • That causese this error: `PHP Parse error: syntax error, unexpected '.' in /home/username/public_html/local/advertising-company/index.php on line 195` – user3286482 Feb 21 '14 at 17:52
  • This should work I just tested !! – Abhik Chakraborty Feb 21 '14 at 17:59
  • @user3286482v you have an error on line 195. Is that where this line is? If you're working with ~200 lines of code and clearly have no idea what you're doing it's going to be next to impossible to tell what your problem actually is. You don't even know. –  Feb 21 '14 at 18:09
0
echo '<td style="word-wrap: break-word;">
 <div><center><a style="text-decoration:none;color:#489FDC;" href="http://local.mysite.com/'.basename(__DIR__).'/'.strtolower(str_replace(" ","-",$row[cities])).'">'.ucwords($row[cities]).'</a></center></div>

';

Move the second echo, and it will show.

DanielDake
  • 25
  • 1
  • 10
  • That causese this error: `PHP Parse error: syntax error, unexpected '.' in /home/username/public_html/local/advertising-company/index.php on line 195` – user3286482 Feb 21 '14 at 17:53
0

you don't need to call echo, you need just concatenate strings, ie.:

echo '<td style="word-wrap: break-word;">
     <div><center><a style="text-decoration:none;color:#489FDC;" href="http://local.mysite.com/'.basename(__DIR__).'/'.strtolower(str_replace(" ","-",$row[cities])).'">'.ucwords($row[cities]).'</a></center></div>
   </td>'; 
ziollek
  • 1,973
  • 1
  • 12
  • 10
  • That causese this error: `PHP Parse error: syntax error, unexpected '.' in /home/username/public_html/local/advertising-company/index.php on line 195` – user3286482 Feb 21 '14 at 17:54
  • you are wrong - it's working ok or you have another error – ziollek Feb 21 '14 at 17:58
0

lol. :)

Just use the method call.

echo " SOME STRING " . basename(__DIR__)  . " SOMESTRING "; 
enterx
  • 869
  • 4
  • 14
0

The index variable should be within single quotes.

echo '<td style="word-wrap: break-word;">
<div>
<center>
<a style="text-decoration:none;color:#489FDC;" href="http://local.mysite.com /"'.basename(__DIR__).'"/'.strtolower(str_replace(" ","-",$row['cities'])).'">'.ucwords($row['cities']).'</a>
</center>
</div>';
DanielDake
  • 25
  • 1
  • 10
-1

try this...

echo "<td style='word-wrap: break-word;'> <div><center><a style='text-decoration:none;color:#489FDC;' href='http://local.mysite.com/'".basename(__DIR__)."'/'".strtolower(str_replace(" ","-",$row[cities]))."''>'".ucwords($row[cities])."'</a></center></div> </td>";

Nishant Solanki
  • 2,119
  • 3
  • 19
  • 32
  • That caused this error: `PHP Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /home/username/public_html/local/advertising-company/index.php on line 195` – user3286482 Feb 21 '14 at 17:55
  • You don't need to echo inside of an echo!!! – Sterling Archer Feb 21 '14 at 17:56
  • How is this supposed to work? You can't concatenate echo as if it was a string or function – Mike Feb 21 '14 at 17:57