In the model class:
public function setPnAttribute($value)
{
$this->attributes['pn'] = strtoupper(trim(substr($value,0,40)));
}
Replace that with the following and it will work perfectly:
public function setPnAttribute($value)
{
$this->attributes['pn'] = normalizer_normalize($value, Normalizer::NFKC);
}
About this part of the code: strtoupper(trim(substr($value,0,50)))
. I recommend you modify the string only after you normalize it so you have a correct and desired output. Otherwise use mbstring instead of the default php functions.
Edit: What i mean by the last part is that the following two examples will always produce correct code:
public function setPnAttribute($value)
{
$this->attributes['pn'] = strtoupper(trim(substr(normalizer_normalize($value, Normalizer::NFKC))));
}
public function setPnAttribute($value)
{
$this->attributes['pn'] = normalizer_normalize(mb_strtoupper(trim(mb_substr($value))), Normalizer::NFKC);
}
nba707 liked this reply
Thank you, I get:
Error Class "App\Normalizer" not found.
I added the \ prefix to Normalizer::NFKC and it works now.
$this->attributes['pn'] = normalizer_normalize($value, \Normalizer::NFKC);
Thank you. Got it working now and moved normalizer into the substr function in the event the bad string has mutti-byte characters,
No worries, make sure you read my last edit on the previous comment. Glad you managed it in the end.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community