0

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

4
Contributors
12
Replies
13
Views
4 Years
Discussion Span
Last Post by mpc123
Featured Replies
  • 2
    diafol 3,720   4 Years Ago

    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. Read More

0

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>";
0

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

Edited by mpc123: need code to help

0

they are in the head of the page

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

2

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.

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

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.