Jump to content

Recommended Posts

First, thanks for the tip with <strong>.

 

Second, the reason it's formatted like that is because the <b> tag came out of a MySQL entry. I'm using a SUBSTRING tag to cut off what is output after x amount of words. It happens to cut off after the <b>, and therefore leaves the rest of the page bold.

Hmm, that still doesn't quite get what I'm going for. Perhaps if I explained myself a little better (by the way, thank you SO much for the help - I really appreciate it).

 

I'm running a query in MySQL to output questions and answers.

 

<?php
  $i=0;
  while ($i < $num and $i < 5) 
  {
  echo "<a href='/accounting-questions/index.php?qid=" . $qid . "'>$question</a><br>";
  echo "<p>$answer</p>"; 
  $i++;
  }
?>

 

In my MySQL database, the $answer field contains HTML (to format the answer how I want it to be). When I use the substring function to cut off $answer after 35 words, I am sometimes left in the middle of a bolded statement (for example: "you <strong>need to" where it cuts off before I include </strong> to end the statement).

 

THEN, on my next loop, the $question and $answer variables are bolded because that <strong> tag never was closed, since the substring only grabbed the first 35 words - before the tag was closed.

 

In my <p> tag, on my style sheet, I have font-weight:normal;    This seems to revert the text back to normal in Chrome and Explorer, but not Firefox. Firefox keeps the <strong> attribute from the first instance.

 

Does this make sense? I'm still fairly new to PHP and MySQL databases, so perhaps there is a better way. Thanks!

Then you go to the other suggestion I made:

 

$answer = str_replace('<strong>', '', $answer);
$answer = str_replace('</strong>', '', $answer);

 

This will remove any strong tags, both opening and closing (this works for the situation where the closing tag also exists in the text.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.