Pergunta

I have job search page which display all jobs with its first 150 chars from jobdescription:

{$listing.JobDescription|strip_tags|truncate:150} in smarty php template file

will return:

Responsibilities:  1) Handle...  

and this is what source code for the above:http://jsfiddle.net/e2ScF/126/ .

Original text built from editor and sample text is at: http://jsfiddle.net/e2ScF/125/

My question is how to make job search result display without < p >,< br/ > and others html tag like:

Responsibilities:1) Handle outbound telesales campaigns for consumer markets (for CallMark clients) by...
Foi útil?

Solução

Your problem is that there are a lot of whitespaces in the middle of the text, so truncate counts them in the 150 limit.

Try with strip:

{$listing.JobDescription|strip_tags|strip|truncate:150}

Outras dicas

Here's a PHP example (See it in action):

<?php
    $string = '<p>
    &nbsp;</p>
<table align="center" border="0" cellpadding="3" cellspacing="0" class="normalword" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color: rgb(0, 0, 0);" width="95%">
    <tbody>
        <tr>
            <td>
                <table align="center" border="0" bordercolor="#666666" cellpadding="3" cellspacing="0" class="normalword" width="100%">
                    <tbody>
                        <tr>
                            <td>
                                <div align="justify">
                                    Responsibilities:&nbsp;<br />
                                    <br />
                                    1) Handle outbound telesales campaigns for consumer markets (for CallMark clients) by utilizing effective presentation and creating positive relationship for all customer contacts with the aim to cross/up selling client&rsquo;s product and services.&nbsp;<br />
';

function firstXChars($string, $chars = 100)
{
    $string = trim(strip_tags($string));
    $string = str_replace(array("\n", "\r"), '', $string);
    preg_match('/^.{0,' . $chars. '}(?:.*?)\b/iu', $string, $matches);
    return $matches[0];
}

echo firstXChars($string);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top