Browse Source

Improve preg_replace

Improve preg_replace
pull/9/head
Danang Probo Sayekti 12 years ago
parent
commit
8f60cc3d90
2 changed files with 7 additions and 7 deletions
  1. +4
    -4
      system/includes/functions.php
  2. +3
    -3
      themes/default/post.html.php

+ 4
- 4
system/includes/functions.php View File

@ -660,13 +660,13 @@ function has_pagination($total, $perpage, $page = 1){
function get_description($text) { function get_description($text) {
$string = explode('</p>', $text); $string = explode('</p>', $text);
$string = preg_replace('/[^,;a-zA-Z0-9_-]|[,;]$/s', ' ', strip_tags($string[0] . '</p>'));
$string = preg_replace('/[^,;a-zA-Z0-9_.-]|[,;]$/s', ' ', strip_tags($string[0] . '</p>'));
if (strlen($string) > 1) { if (strlen($string) > 1) {
return $string; return $string;
} }
else { else {
$string = preg_replace('/[^,;a-zA-Z0-9_-]|[,;]$/s', ' ', strip_tags($text));
$string = preg_replace('/[^,;a-zA-Z0-9_.-]|[,;]$/s', ' ', strip_tags($text));
if (strlen($string) < config('description.char')) { if (strlen($string) < config('description.char')) {
return $string; return $string;
} }
@ -681,12 +681,12 @@ function get_description($text) {
function get_teaser($text, $url) { function get_teaser($text, $url) {
if (strlen(strip_tags($text)) < config('teaser.char')) { if (strlen(strip_tags($text)) < config('teaser.char')) {
$string = preg_replace('/[^,;a-zA-Z0-9_-]|[,;]$/s', ' ', strip_tags($text));
$string = preg_replace('/[^,;a-zA-Z0-9_.-]|[,;]$/s', ' ', strip_tags($text));
$body = $string . '...' . ' <a class="readmore" href="' . $url . '#more">more</a>' ; $body = $string . '...' . ' <a class="readmore" href="' . $url . '#more">more</a>' ;
echo '<p>' . $body . '</p>'; echo '<p>' . $body . '</p>';
} }
else { else {
$string = preg_replace('/[^,;a-zA-Z0-9_-]|[,;]$/s', ' ', strip_tags($text));
$string = preg_replace('/[^,;a-zA-Z0-9_.-]|[,;]$/s', ' ', strip_tags($text));
$string = substr($string, 0, strpos($string, ' ', config('teaser.char'))); $string = substr($string, 0, strpos($string, ' ', config('teaser.char')));
$body = $string . '...' . ' <a class="readmore" href="' . $url . '#more">more</a>' ; $body = $string . '...' . ' <a class="readmore" href="' . $url . '#more">more</a>' ;
echo '<p>' . $body . '</p>'; echo '<p>' . $body . '</p>';


+ 3
- 3
themes/default/post.html.php View File

@ -21,9 +21,9 @@
<?php endif;?> <?php endif;?>
<div class="share"> <div class="share">
<h4>Share this post</h4> <h4>Share this post</h4>
<a class="twitter" href="https://twitter.com/share?url=<?php echo $p->url ?>&text=<?php echo $p->title?>">Twitter</a>
<a class="facebook" href="https://www.facebook.com/sharer.php?u=<?php echo $p->url ?>&t=<?php echo $p->title?>">Facebook</a>
<a class="googleplus" href="https://plus.google.com/share?url=<?php echo $p->url ?>">Google+</a>
<a class="twitter" target="_blank" href="https://twitter.com/share?url=<?php echo $p->url ?>&text=<?php echo $p->title?>">Twitter</a>
<a class="facebook" target="_blank" href="https://www.facebook.com/sharer.php?u=<?php echo $p->url ?>&t=<?php echo $p->title?>">Facebook</a>
<a class="googleplus" target="_blank" href="https://plus.google.com/share?url=<?php echo $p->url ?>">Google+</a>
</div> </div>
</div> </div>
<?php endif;?> <?php endif;?>


Loading…
Cancel
Save