문제

I'm using XPath to get div contenteditable's content and insert it in DB. But when I output the content there are no new lines.

$divs = $xpath->query('//div');
foreach($divs as $book) {
$text = nl2br($book->textContent);
}

What am I doing wrong? Thanks in advance :)

도움이 되었습니까?

해결책

$book->textContent strips all markup from the content [1], such as <div> which are naturally inserted when you hit enter on an contenteditable-Element. Therefore all this function returns is a concatenation of pure text.

I'm not sure what your goal is, but you might look into $your_DOMDocument->saveHTML($book). This will return the actual HTML of each $book including the surrounding <div>.

[1]: see the DOM Specifications

다른 팁

You might be able to set a xml:whitespace="preserve" attribute on the element that has content editable and it come through using the xml api.

Failing this a solution would be to add a keypress handler to the content editable div that catches an enter and replaces it with a <br/> at the cursor position.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top