Viewed   59 times

I want to save html-formatted text to database, but when I do that it is don't save html-symbols like < / > ' and others This is how I read article from database for editing:

<p class="Title">??????????? ???????:</p>
    <textarea name="EN" cols="90" rows="20" value="<?php echo htmlentities($articleArr['EN'], ENT_QUOTES, "UTF-8"); ?>" ></textarea>

after this generates such html-code:

<p class="Title">??????????? ???????:</p>
    <textarea name="EN" cols="90" rows="20" value="&lt;p class=&#039;Title&#039;&gt; ?????? &lt;/p&gt;" ></textarea>

So, I expect that this text will appear in my text field, in html-code of this page it is, but in text area is no.

In database I save it as:

<p class="Title"> Hello </p>

So how can I do the follow:

  1. Read from database html-formattedtext.
  2. Show it in textarea element.
  3. Edit and save it back to database.

Help me please, how can I save such texts properly, Thanx!

 Answers

5

Try using htmlspecialchars() on the string to put into the DB, and then, when pulling it back out, use htmlspecialchars_decode(). Might make a difference.

Monday, October 10, 2022
 
3
<form name="add" method="post">
     <p>Age:</p>
     <select name="age">
        <option value="1_sre">23</option>
        <option value="2_sam">24</option>
        <option value="5_john">25</option>
     </select>
     <input type="submit" name="submit"/>
</form>

You will have the selected value in $_POST['age'], e.g. 1_sre. Then you will be able to split the value and get the 'stud_name'.

$stud = explode("_",$_POST['age']);
$stud_id = $stud[0];
$stud_name = $stud[1];
Tuesday, October 4, 2022
5

The usual workflow:

  1. Provide a Javascript rich-text editor for your users such as TinyMCE: http://tinymce.moxiecode.com/
  2. Grab the source generated by the RTE and filter it through HTML Purifier before saving to the database.
  3. Escape the existing HTML: <div id="myHtml" style="display: none"><?php echo htmlentities($html); ?></div>
  4. Re-populate the RTE via Javascript - in the case of TinyMCE as follows: tinyMCE.activeEditor.setContent($('#myHtml').html());

You can also load the HTML content via AJAX.

Tuesday, December 27, 2022
 
ghaag
 
1

As I have worked with HTML parsing and text2speech here you can go with 2 steps 1.get Attribute string from HTML file with below code works in iOS7+

As per your client perspective : if there is any API in market for HTML2Speech may be its Paid or you are depended on that API if you use any. While Native framework will help same what you/client wants.

Step 1:

[[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUTF8StringEncoding] 
                                 options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
                                           NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)} 
                      documentAttributes:nil error:nil];

Then you can pass this Attributed String in AVSpeechUtterance

Step 2: use below method to get HTML2String:

/**
 *  "ConvertHTMLtoStrAndPlay" : This method will convert the HTML to String 
 synthesizer.
 *
 *  @param aURLHtmlFilePath : "object of html file path"
 */
-(void)ConvertHTMLtoStrAndPlay:(UIButton*)aBtnPlayPause
                isSpeechPaused:(BOOL)speechPaused
      stringWithHTMLAttributes:(NSAttributedString*)aStrWithHTMLAttributes
{

    if (synthesizer.speaking == NO && speechPaused == NO) {

        AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:aStrWithHTMLAttributes.string];
        //utterance.rate = AVSpeechUtteranceMinimumSpeechRate;

        if (IS_ARABIC) {
            utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"ar-au"];
        }else{
            utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-au"];
        }

        [synthesizer speakUtterance:utterance];
    }
    else{
        [synthesizer pauseSpeakingAtBoundary:AVSpeechBoundaryImmediate];
    }

    if (speechPaused == NO) {
        [synthesizer continueSpeaking];
    } else {
        [synthesizer pauseSpeakingAtBoundary:AVSpeechBoundaryImmediate];
    }

}

and as usual while you need to stop use below code to stop Speech.

/**
 *  "StopPlayWithAVSpeechSynthesizer" : this method will stop the playing of audio on the application.
 */
-(void)StopPlayWithAVSpeechSynthesizer{

    // Do any additional setup after loading the view, typically from a nib.
    [synthesizer stopSpeakingAtBoundary:AVSpeechBoundaryImmediate];
}

Hope This will help you to get HTML2Speech feature.

Wednesday, December 14, 2022
2

Officially an img element should not have child elements/html, so the behavior when you modify the innerHTML is undefined.

Instead of adding innerHTML to your elements, you could try adding a data attribute to each:

var fnSpeech = function () {
    responsiveVoice.speak(this.getAttribute('data-speech-text'), 'Dutch Female');
};

for (i = 0; i < SpeechList.length; i++) {
    SpeechList[i].addEventListener("click", fnSpeech, false);
}

function fnHandleText(FileText) {
    var TextArray = FileText.split(",");
    console.log(TextArray);
    for (var i = 0; i < TextArray.length; i++) {
        // Set the text for non-img elements
        document.getElementById("zin" + (i + 1)).innerHTML = i + 1
        document.getElementById("zin" + (i + 1)).setAttribute('data-speech-text', TextArray[i]);
    }
}

I made a couple edits to make my suggested code more compatible with yours


Here is a jsFiddle to show the functionality

Monday, August 1, 2022
 
tomdogg
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :