开发者

Converting ^M Character to Whitespace without Line Break using PHP

开发者 https://www.devze.com 2023-04-07 14:21 出处:网络
I\'m trying to convert ^M character to a white space character, but having hard time doing this. In PHP, I used \"wb\" option so, it wouldn\'t write DOS character into the file. fopen(\"file.csv\", \

I'm trying to convert ^M character to a white space character, but having hard time doing this.

In PHP, I used "wb" option so, it wouldn't write DOS character into the file. fopen("file.csv", "wb") It was successful, but still has line breaks instead of ^M

$fp = fopen("file.csv"开发者_如何学Python, "wb");
$description =nl2br( $product->getShortDescription());
$line .= $description . $other_variables . "\n";
fputs($fp, $line);

but I still see line break within the description, is there any way to remove ^M and replace it with possibly a whitespace.

Also used dos2unix, when it was in regular file "w" mode. It removes all ^M characters, but the file still has line breaks where there was ^M. I really need it to be all on one line for my CSV file to work.

Thank you.


I think you're asking how to remove all the newline/line feed/carriage return characters from the description. If so:

$description =str_replace(array("\r", "\n"), '', nl2br($product->getShortDescription());
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号