How to store efficiently all text edits? - php

I'm building PHP Symfony 4 + Vue.js app. And one of it's part — text editor, which remembers all edits in text. I saw how the same problem solved in ACE editor — they save every letter, but I don't need such precision. It will be enough to store substrings with type of action. Something like:
{ action: add, from: 0, to: null, text: "New string" }
And result text will be: "New string". Then I changed something:
{ action: add, from: 3, to: 4, text: 'Delicious S' }
And result became: "New Delicious String". Storing such "commits" with text, I can reconstruct state of text in a some moment, beeing applied published commits until required moment.
Do I think correct or are there some better way?
Maybe you know some efficient algorithm or data structure to store such task?
What edit coordinates in text should I use, to work with them more efficiently?

Related

how to send html formatted text to text filed in template docusign?

hi i want to send bullet point to docusign template text field
but when i send it as a html it will print as it is, even the [\r\n][1] is not working how i can send the formatted text so i can you the bullet points
this is the text i want to show in format
<ol><li>this is the test term </li><li>this is the test term again </li><li>this is the last term for testing purpose</li></ol>
text field in template
this is the way i want to show
this is the way its being shown right now
updated
how add new line using Unicode ?
updated 18-Nov-2020
I want the answer for PHP language please , using docusign SDK
The DocuSign text fields can only handle plain text, not HTML.
But good news: that includes all Unicode characters including Unicode bullet points such as this triangular bullet point: ‣
So your application can add bullet points to DocuSign text fields.
As an alternative, your application could create a custom document for the envelope in addition to or instead of the template's document(s).
You could create the additional document using HTML or create a PDF document on the fly.
Added (and updated)
Tested! It works! To add a new line, I add new line character to the text tab's value.
If your computer language interpolates character sequences, that'd be
value = "‣ line 1\n‣ line 2"
Working Node.JS example:
...
let textTab1 = docusign.Text.constructFromObject({
anchorString: "/sig1/",
anchorXOffset: "120",
height: "30",
value: "‣ line 1\n‣ line 2",
width: "120"
});
let textTabs1 = [textTab1];
let tabs1 = docusign.Tabs.constructFromObject({
signHereTabs: signHereTabs1,
textTabs: textTabs1
});
...
Result (screenshot):

PHP - Search a string for specific values, return related text

I'm using a PDF reader for PHP to load a big .pdf file that will store each page as a seperate, huge string in a big array.
This results in an output like this:
"Official certificate Surname: Doe First Name: John Date of birth:
10th of June, 1970 Place of Birth etc etc..."
How do I search for the specific text "Surname" and then select whatever text comes after that until "First Name" to return it as $var_surname.
The syntax used in the .pdf file will always be the same, so I have no problem using such absolute conditions for searching for the text.
I genuinely don't know where to start. Sorry if this question feels vague, let me know if more information is required.
if(preg_match('/Surname:[\s]+([\w]+)[\s]+First/i', $input, $matches)){
echo $matches[1];
}
will echo Doe
You could use a function like strrpos() to find out where the string surname ends, at what position. Then you could use strpos() to find out there the strin first name starts, what position. Afthr you know the positions you could chop between them and store it as $var_surnam . (using substr()). Hope this helps.
It would be better to figuring out the pattern and then write some methods. After that just pass the string by calling the methods. Based on given information this my best possible answer. Surely you will need to use builtin String methods.

PHP Mysql CodeIgniter Converting characters to symbols in very bizarre circumstances

PHP Mysql CodeIgniter Converting characters to symbols in very bizarre circumstances
Application Built on CodeIgniter.
Has been running for over a year. No problems.
Client fills in a form about a customer.
A simple trim($_POST['notes']) captures textarea form field text and saves to MySQL
no error reported in PHP or JavaScript
The other day I notice some text the client has entered, has had the brackets used in the text "()" replaced with the equivalent "()
I think... "That's strange... I don't recall any reason why those characters would have been replaced like that.!"
I take a look ... and a day later... here is my madness revealed:
The text in question is verbatim "
Always run credit card on file (we do not charge this customer for pick-up or return)
"
No matter what I did or changed on the code side.. I could not prevent the PHP... OR Javascript... Or MySQL... OR alien beings... - or whoever the heck is doing it - from converting the "()" in the text to "(). And I tried many things like cleaning the string in all ways known to man or god. Capturing the string previous to sending just before saving to the database. And the conversion would always take place just before the save to MySQL. I tried posting in different forms and fields... Same thing every time... could not stop the magic conversion to "().
What in the name of batman is in this magical text that is causing this to happen?? is it magic pixie dust sprinkled on to godaddy server it is running on??? 0_o
.......
Being the genius that I am 0_0 I decide to remove one word from the paragraph at a time.
Magically... as all the creatures of the forest gathered around - as I finally got to the word "file" in the paragraph, and removed it !!! Like magic - the "()" stay as "()" and are NOT converted to "()?!?!???!?!? :\ How come??I simply removed the word "file" from the text... How could this change anything?? What is the word "file" causing to change with how the string is saved or converted??
OK -So I tested this out on any and every form field in the app. Every single time, in any field, if you type the word "file" followed by a "(" it will convert the first "(" to "(; and the very next ")" to ")
So.. if the string is:
"file ( any number of characters or text ) any other text or characters"
On post, it will be converted mysteriously to:
"file ( any number of characters or text &#41 any other text or characters"
Remove the word "file" from the string, and you get:
"( any number of characters or text ) any other text or characters"
The alien beings return the abducted "()"
Anyone have a clue what the heck could be going on here?
What is causing this?
Is the word "file" a keyword that is tripping some sort of security measures? interpereting it as "file()"???
I dunno :\
It's the strangest thing I ever saw... Except for that time I walked in on Mom and Dad 0_o
Any help would be greatly appreciated, and I will buy you a beer for sure :)
The very large headed, - (way to much power for such tender egos) -, Noo-Noos here at stack have paused this question as "Off topic" LOL... honest to God these guys are so silly.
So - in an effort to placate the stack-gestapo - I will attempt to edit this question so that it is... "on topic"??? 0_o ... anything for you oh so "King" Stack Guys O_O - too bad you would never have the whit to ever notice such a bug... maybe some day. ;)
Sample code:
<textarea name="notes">Always run credit card on file (we do not charge this customer for pick-up or return) blah blah</textarea>
<?php
if(isset($_POST['notes']){
$this->db->where("ID = ".$_POST['ID']);
$this->db->update('OWNER', $_POST['notes']);
}
?>
Resulting MySQL storage:
"Always run credit card on file (we do not charge this customer for pick-up or return) blah blah"
InnoDB - Type text utf8_general_ci
I am not looking for a way to prevent it, or clean it... I am clearly asking "What causes it"
/*
* Sanitize naughty scripting elements
*
* Similar to above, only instead of looking for
* tags it looks for PHP and JavaScript commands
* that are disallowed. Rather than removing the
* code, it simply converts the parenthesis to entities
* rendering the code un-executable.
*
* For example: eval('some code')
* Becomes: eval('some code')
*/
$str = preg_replace('#(alert|cmd|passthru|eval|exec|expression|system|fopen|fsockopen|file|file_get_contents|readfile|unlink)(\s*)\((.*?)\)#si', "\\1\\2(\\3)", $str);
This is the part of XSS Clean. (system/core/Security.php)
If you want the filter to run automatically every time it encounters POST or COOKIE data you can enable it by opening your application/config/config.php file and setting this:
$config['global_xss_filtering'] = TRUE;
https://www.codeigniter.com/user_guide/libraries/security.html
try something like this
$this->db->set('OWNER', $_POST['notes'],FALSE);
$this->db->where('ID ', $_POST['ID']);
$this->db->update('table_name');
Men I think Is in your server. If Ur using Wamp try to check if you have miss Install some arguments in xhtml. This is my Idea. it's related on my experience in CodeIgniter. hope U will response if you want some advice.
Use utf8 encoding to store these values.
To avoid injections use mysql_real_escape_string() (or prepared statements).
To protect from XSS use htmlspecialchars.
How ever not sure what is the issue in ur case..
Probably try using some other sql keywords in the string and verify the solution.
Try replacing the &#40 and the &#41 with ( and ) using str_replace
If you are storing &#40 and &#41 in your database then you should try replacing it on output if not try and replace it before input.
I'm not sure if this would work, but you could try inserting a slash in or before the word 'file':
fi\le ( any number of characters or text ) any other text or characters

substr and strlen explanation

Ok guys, this question is related to my previous one.
If I have set $textlimit = 500; that will limit my text to 500 characters.
Is there any way to "avoid" text limit, and then onclick function load rest of it?
For example, if I set:
$textpart = substr($fulltext, 0, 400);
$textpart will only contain 400 characters of string.
My question is, how to declare variable, which will contain the rest of the text which is much longer than 500 characters?
Example of variables:
$fulltext //Contains full text, but is limited to 500 characters.
$textpart //Contains part of the text, substr 400 characters out of 500.
$textrest //This variable to "hold" rest of the text, after 400 characters of $textpart.
Like I've asked in previous question, I wanted to make expand and collapse button, I now know how to do that, but I don't know how to divide text.
Form would go like this:
Random text here(400 characters long)
Random image for expand
After declared onclick function I, load rest of the text (Over 500 characters).
Random image for collapse
After declared onclick function collapse and return to previous state - citation 1.
I hope I explained my question the right way. I would really appreciate any kind of help, if I can choose, I would like just basic explanation on how to that, because I want to learn that, not copy/paste solution (it is easier, but I will not learn much).
Thanks in advance.
$textrest = substr($fulltext, 400)
$fulltext = substr($fulltext, 0, 500);
$textpart = substr($fulltext, 0, 400);
$textrest = substr($fulltext,400,strlen ( $fulltext ));
If I understand you correctly you want to show the user an initial page that shows only the first X characters and then show all the characters when the users clicks on the text.
There are three strategies to do this. From easy to hard:
Output the shortened text and include a link that will reload the whole page but with the whole text
Output all the text and use css and JavaScript to hide/show any overflow
Output the shortened text and perform an Ajax call to load the extra characters and append
Options 2 and 3 require the use of client side JavaScript and are therefore not pure PHP solutions.
Option 1 is a matter of adding a $_GET variable, e.g. ?expand=para1, to your url and expanding the text identified in PHP by $_GET['expand'].
Do not make the mistake of thinking PHP is still running on the page in the browser. Only JavaScript can run in the browser on the web page. (Not strictly true I know, but true enough in reality.)

how to set character to big size without press capslock

dear all..i want my input form automatically make all character become big size..
and also without press a capslock button...i want all data which have been input into DB in capital format..what's code to make it?
One simple way in jQuery is to convert the the value to uppercase after every keyup event:
$(document).ready(function(){
$('#myfield').keyup(function() {
var t = $(this);
t.val(t.val().toUpperCase());
});
});
Remember that this only changes the value in the UI on the client. When the user submits the form, it will send this uppercased value, but a malicious user could send data that was not uppercased, so you probably want to use an upcase method on your server, either in your CGI code (PHP, Perl, Java or whatever you're using), or in your SQL insert statement.
As Matthew said, strtoupper() will work.
$str = "Mary Had A Little Lamb and She LOVED It So";
$str = strtoupper($str);
echo $str; // Prints MARY HAD A LITTLE LAMB AND SHE LOVED IT SO
Using Javascript to filter something that is going into a database, is bad. What if the user decides to turn of Javascript? You can do it, but it will have to be done again when in the backend code, so it's a waste of time for something like this :)
You can use the PHP function strtoupper.

Categories