Ben etiketleri ile çevrili olması dizenin ilk kelime istiyorum. Benim koduyla tüm kelimeleri insted ile çevrili olur.
The code is for a wordpress so the_title is the title of the post. Eg. Hello World.
I want it to be <span>Hello </span>World
.
<?php
$string = the_title('', '', false);
$pattern = '^(\S+?)(?:\s|$)^';
$replacement = '<span>$1</span>';
$string = preg_replace($pattern, $replacement, $string);
?>
<h2><a href="<?php the_permalink(); ?>"><?=$string?></a></h2>
Benim kötü İngilizce için üzgünüm :)
MY SOLUTION:
<?php
$string = the_title('', '', false);
$pattern = '/\S+/';
$replacement = '<span>$0</span>';
$string = preg_replace($pattern, $replacement, $string, 1);
?>
<h2><a href="<?php the_permalink(); ?>"><?=$string?></a></h2>