On my slug column I set the limit is varchar = 100 and the values will store like this
how-do-i-truncate-a-string-with-dynamic-length-url-slug
I want the slug will be a unique key so I update the slug value with last auto increment id and new slug value is :
how-do-i-truncate-a-string-with-dynamic-length-url-slug-10
So here the last auto increment will be a big number at the end..
preg_replace('/\s+?(\S+)?$/', '', substr($slugwithautoincrement, 0, 101));
With this preg_replace it will remove my auto increment number
Question :
How do I truncate the value fix to 100 characters without remove the last auto increment number?
So result should be :
how-do-i-truncate-a-string-with-[....remove from here...]10
If you can’t truncate before appending the auto increment value: