Link to home
Start Free TrialLog in
Avatar of maccaj51
maccaj51Flag for Afghanistan

asked on

making first word bold

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'] . "" ;}?>
Avatar of no worries :-) no nothing
no worries :-) no nothing
Flag of Greece image

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


Use this with: <b>text<b>
Parse the first word and wrap a SPAN tag around it.

.firstword { color:red }

<h1><span class="firstword">The</span> Header</h1>
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
Avatar of cloud-9
cloud-9

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

ASKER CERTIFIED SOLUTION
Avatar of cloud-9
cloud-9

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of maccaj51

ASKER

Good Solutions... if not a bit long winded
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.