We help IT Professionals succeed at work.

making first word bold

maccaj51
maccaj51 asked
on
is there anyway of making the first word of my H1 retrieved with this code have different css styling to the other words?

<?php $result = mysql_query("SELECT * FROM pages WHERE id='$id'"); while($row = mysql_fetch_array($result)) {echo $row['h1'] . "" ;}?>
Comment
Watch Question

Use substr, sybntax:
string substr ( string $string , int $start [, int $length ] )
example : substr("examplef", 1, 3);  // returns "xam"


Use this with: <b>text<b>
JF0

Commented:
Parse the first word and wrap a SPAN tag around it.

.firstword { color:red }

<h1><span class="firstword">The</span> Header</h1>
Avinash ZalaWeb Expert

Commented:
try this:

If your string is "demoText" then do like below php code:

<?php

  $string ='demotext';

  echo '<strong>'.substr($string,0,1).'</string>'.substr($string,1,strlen($string)-1);

?>

this will make the first character bold.

Hope this helps
Addy

Commented:
Explode it into an array, replace the first word, and then implode:
$string = "This is string";
$exploded = explode(" ", $string, 2);
$style = "<h1><span>{$exploded[0]}</span>{$exploded[1]}</h1>";

//Then to style it simply use
h1 span {
    font-weight:bold;
}
//If you only need to make it bold, user <b> tags instead of spans and extra css

Open in new window

Commented:
Oops forgot to change my description, It should be explode it with a limit, then put the two parts into a string.

Author

Commented:
Good Solutions... if not a bit long winded

Commented:
Well most people prefer complete and detailed solutions. First off, it is easier for people who have a similar issue to refer to and adapt it to their situation. Also it is usually more clear to the asker to figure out what the code means.