Remove white space characters on both sides (rim function cannot remove half width spaces)

Time:2022-5-10

How to display the text entered by the user

Remove white space characters on both sides (rim function cannot remove half width spaces)

This is a user input copied from a database. First of all, it is not rich text, but it should be displayed in a beautiful format (roast).

phpHow to handle characters?

$intro_ arr=explode("\n",$str); // Split into arrays based on line breaks
$new_str = '';
foreach($intro_arr as $item) {
    //Exclude white space characters
    if(!empty($item)){
        //Remove blank characters on both sides? The trim function cannot remove half width spaces.
        $item = mb_ ereg_ replace('^( | )+','', $item);// Remove left margin
        $item = mb_ ereg_ replace('( | )+$','', $item);// Remove right margin

        //Set of labels,,
        $item_p = '<p style="text-indent:2em;">'.trim($item).'</p>';
        $new_str .= $item_p;
    }
}

This work adoptsCC agreement, reprint must indicate the author and the link to this article

focus

Recommended Today

Springboot Kafka configuration with permission allows you to avoid detours

spring.kafka.producer.bootstrapServers=192.168.211.54:4988 spring.kafka.producer.properties.sasl.mechanism=PLAIN spring.kafka.producer.properties.security.protocol=SASL_PLAINTEXT spring.kafka.producer.properties.sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username=\”caadmin\” password=\”R5s^[email protected]\”; Or hard coded public static void main(String[] args) throws Exception { try { String topicName = “mytopic”; String key = “key1”; String value = “Value-1”; Properties prop = new Properties(); prop.put(“bootstrap.server”,”localhost:9092″); prop.put(“key.serializer”,”org.apache.kafka.common.serialization.StringSerializer”); prop.put(“value.serializer”,”org.apache.kafka.cpmmon.serialization.StringSerializer”); Producer<String, String> producer = new KafkaProducer<>(prop); ProducerRecord<String, String> record = new ProducerRecord<>(topicName,key,value); producer.send(record); producer.close(); System.out.println(“SimpleProducer […]