maccaj51
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'] . "" ;}?>
<?php $result = mysql_query("SELECT * FROM pages WHERE id='$id'"); while($row = mysql_fetch_array($result)
Parse the first word and wrap a SPAN tag around it.
.firstword { color:red }
<h1><span class="firstword">The</spa n> Header</h1>
.firstword { color:red }
<h1><span class="firstword">The</spa
try this:
If your string is "demoText" then do like below php code:
<?php
$string ='demotext';
echo '<strong>'.substr($string, 0,1).'</st ring>'.sub str($strin g,1,strlen ($string)- 1);
?>
this will make the first character bold.
Hope this helps
Addy
If your string is "demoText" then do like below php code:
<?php
$string ='demotext';
echo '<strong>'.substr($string,
?>
this will make the first character bold.
Hope this helps
Addy
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
string substr ( string $string , int $start [, int $length ] )
example : substr("examplef", 1, 3); // returns "xam"
Use this with: <b>text<b>