How to change letter to another or words to ***?

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
ASHKAR
User
Posts: 26

How to change letter to another or words to ***?

Post by ASHKAR »

Hi everyone,
I have a question if i want to change specific letters or words (such as bad words) and change it to any thing else
Lets say letter
If i have
Ē, É, Ě, È, Ê, etc
And want to chage all to E

Or words from bad words to ***

Is there a way?


arbei
User
Posts: 9384

Post by arbei »

You need to convert the ViewValue property of the field object yourself by Row_Rendered server event. You may also google for such functions.


ASHKAR
User
Posts: 26

Post by ASHKAR »

Is Row_Rendered change the data before insert into database? or change it after select from db?


arbei
User
Posts: 9384

Post by arbei »

Row_Rendered server event is fired before the database value is outputted as HTML. If you prefer modifying data before inserting to database, you should use Row_Inserting and Row_Updating server events.


ASHKAR
User
Posts: 26

Post by ASHKAR »

Thanks,
it worked fine for specific input field, but how to make it run for all input fields ?


arbei
User
Posts: 9384

Post by arbei »

You need to add your code for each field that you need to change, you may loop through $this->Fields.


ASHKAR
User
Posts: 26

Post by ASHKAR »

i can use this to all field in a table

$rsnew = str_replace(['A', 'B', 'C'], 'D', $rsnew);

this will replace A or B or C to D

we should use this code for all tables using Row_Inserting


arbei
User
Posts: 9384

Post by arbei »

You should not do that, not every value is string, you better loop and check if value is string and is not null first.


ASHKAR
User
Posts: 26

Post by ASHKAR »

Thanks

Do you mean some thing like that ?

if (is_string($rsnew) && !is_null($rsnew)) {
	$rsnew = str_replace(['A', 'B', 'C'], 'D', $rsnew);
}

arbei
User
Posts: 9384

Post by arbei »

You may read foreach, $rsnew is an associative array.


Post Reply