Start New Discussion within our Web Development Community

Hi I have an issue whereby I need to replace characters in a field and also narrow the amount of characters down, but sturggling with putting them both together

I have 2 seperate lines of code to do them both seperately that work, but struggling to get them together btw $txt7 is also the field description, its just the way it has ended up trying different ways to get them together :)

'. str_replace('*','' . $file['field2'] . '',trim($file['description'])) . '<p>

<?php

if(strlen($txt7)>200){
echo substr($txt7, 0, 200) . '…';
}
else {
echo $txt7;
}

?>

Hope you can help

Thanks

I think I understand what you're trying to do.

$raw_text = trim($file['description']);

if(strlen($raw_text)>200) { $raw_text = substr($raw_text, 0, 200) . "..."; }

$final_text = str_replace('*', $file['field2'], $raw_text);

echo "<p>$final_text</p>";

Hi thanks for your help

the code itself just echos out on to the page now though?

This is the bit I need to edit really if you can help with that

<?php
if(strlen($txt7)>200){
echo substr($txt7, 0, 200) . '…';
}
else {
echo $txt7;
}
?>

Thanks

they are in the head of the page

<?php$txt2 = "' . $file['field2']. '"; $txt7 = "' . $file['description']. '"?>

How about the mb_* functions:

echo mb_strimwidth($txt7, 0, 203, "...");

You need to add the number of characters in the append parameter (#4) to the end trim parameter (#3). Start trimming on parameter #2, using the string #1.

Comments
Nice use of mb_strimwidth() I knew there was a better function but it wasn't coming to me :)

I couldnt get it to work so just set up another field and updated with same info and used 2 fields.

Thanks for help anyway

This question has already been answered. Start a new discussion instead.