1
$text = '<p>Download game <a href="">Avatar</a> for <b>Iphone 3GS</b></p>';
<?php 
echo strip_tags(substr($text, 0, 10))." ..."; 
?>

But resut is ....

How to fix it?

4 Answers 4

3

Place your $text definition within <?php ?> tags. Otherwise, PHP treats it as plain output.

Sign up to request clarification or add additional context in comments.

Comments

0

Try this

<?php 
  $text = '<p>Download game <a href="">Avatar</a> for <b>Iphone 3GS</b></p>';
  echo strip_tags(substr($text, 0, 10))." ..."; 
?>

Comments

0

I tried with:

<?php

 $text = '<p>Download game <a href="">Avatar</a> for <b>Iphone 3GS</b></p>';
 echo strip_tags(substr($text, 0, 10))." ...";

?>

And the output was Downloa ...

What do you expect to be shown?

Comments

0

As pointed out the $text variable declaration needs to be within the PHP section.

Also I'd suggest that you strip_tags first and then substr the result as otherwise strip_tags won't be able to remove all of the tags.

i.e:

<?php
$text = '<p>Download game <a href="">Avatar</a> for <b>Iphone 3GS</b></p>';
echo substr(strip_tags($text), 0, 10)." ...";

and even possibly as follows: so you'd get Download game Avatar ...Iphone 3GS

<?php
$text = '<p>Download game <a href="">Avatar</a> for <b>Iphone 3GS</b></p>';
$ntext = strip_tags($text);
echo substr($ntext, 0, 20). 
     (strlen($ntext) > 20 ? "...".substr($ntext, min(20,strlen($ntext)-10)):"");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.