Write HTML and PHP in the same line

Asked

Viewed 248 times

1

<p> " <?=$testemunhos[$i]['testemunho']?> " <p>

I want to write in the same line, but this getting so

inserir a descrição da imagem aqui

and I wanted it like this

" Lorem ipsum dolor sit Amet, consectetur adipiscing Elit. Ut sed magna aliquet, congue nunc at, lacinia neque. "

any hint?

<? $testemunhos=$testemunhos->getTestemunhos();  ?>


                            <ul class="rslides" id="comentarios">
                                <? for($i=0;$i<count($testemunhos);$i++){ ?>
                                    <li>
                                        <div class="avaliacao">
                                             <p> " <?=($testemunhos[$i]['testemunho']) ?> " <p>
                                        </div>
                                    </li>
                                <? } ?>     
                            </ul>
  • You need to specify a container size for your content, so when the text is larger than the size of your container, it will throw the content down.

  • 2

    Give a CTRL+U and look at the source code that shows the HTML. It seems to me that the PHP code is returning another paragraph.

  • yes, this returns 3 paragraphs, 2 for the " and 1 for the text

  • Try to remove the paragraphs with the str_replace.

  • Look at the browser source code and see what the HTML shows.

  • https://imgur.com/a/ciOOMI8

  • You’re opening two <p>... the last had to be </p>.

  • yes, you’re right there was an error in the code, I’ve solved it but the problem continues

  • I discovered the problem, but I still don’t know how to solve it. I’m using the CKEDITOR and it will be stored in the Database as a paragraph.

Show 4 more comments

1 answer

4


What is happening is that the text returned in <?=$testemunhos[$i]['testemunho']?> is coming with a paragraph, something like that:

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Ut sed magna aliquet, congue nunc at, lacinia neque.</p>

With this, the browser will close the <p> which is already in HTML, because you can’t nest one paragraph inside the other, and it’s getting like this:

<p> " </p>
<p>Lorem ipsum dolor sit amet...</p>
"
<p></p>

Another thing is that you didn’t close the <p> HTML, you opened it twice:

<p> " <?=($testemunhos[$i]['testemunho']) ?> " <p>
 ↑                                              ↑

The right thing would be:

<p> " <?=($testemunhos[$i]['testemunho']) ?> " </p>
 ↑                                              ↑
 abrindo                                     fechando

But even correcting the second <p> for </p>, will still give problem with the <p> coming from PHP, as I said at the beginning.

What can be done is delete tags <p> of PHP using preg_replace:

<p> " <?=preg_replace('/<\/?p>/', '', $testemunhos[$i]['testemunho'])?> " </p>
  • thanks, that’s just what I was looking for

  • You are welcome. But the ideal thing was to delete the <p> tags when saving to the database.

  • If you already have <p> in the database, can simply not put other <p> outside

  • @bfavaretto I thought that too, but the quotes have to be inside the <p>.

  • It’s true... ...

  • 1

    The regex may be only /<\/?p>/ (the bar is optional, so it already covers the opening and closing of the tag)

  • 1

    @hkotsubo That’s right, thanks! I knew I had something in that regex to improve rs

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.