Here's the problem:
I have couple of pages which gets its content from a database. The content is displayed in a Literal control kept on an asp.net page.
The article sometimes gets quite long so I want to break the content into two parts using a client script. Unfortunately I cannot change the query to pull data partially. The entire data has to come.
What I want is that when the page (http://mysite.com/showpage.aspx?pid=45) or any other page is opened, I show the first 500 words in that literal control. A Link gets generated below the 500 words which says 'Click Here to View More...'
On clicking this link, a postback occurs and this time the entire content is shown to the user. I understand there is an extra roundtrip required but that's ok for my users.
How can I create such a functionality? Please help me with the script. Thanks.
i use the following jQuery function to shorten a div of text and add a more button.
http://www.reindel.com/truncate/
Where, in the example below, 120 is the character limit.
Character limit:
An acceptable set of characters
(designated by a regular expression)
to truncate in front of, once the max
has been reached. If an acceptable
character is not found at the max, the
plugin will traverse the string
backwards until one is found. If none
is found, the string will not
truncate. The default value is a
single white space character.
$("#contentDiv").truncate( 120,{
chars: /\s/,
trail: [ " ( <a href='#' class='truncate_show'>more</a> . . . )",
"( . . . <a href='#' class='truncate_hide'>less</a> )" ]
});
Basically you need to have a function to count the number of words including the space and other characters.
If the total is exceeding 500 words, wrap the 500 characters with the hyperlink and take only the first 500 characters.
Alternatively you might want to try any JQuery tooltip.
Hope this helps,
hadi
Related
I wanted to verify a text in a webpage exist for 2 times or ‘n’ times. I have used “Page Should Contain” keyword but it says “Pass” when it identifies single occurrence. I don’t want to verify using locator.
Ex: I want to verify the text "Success" is available in a current webpage for 3 times using robot framework
Any inputs/suggesstions would be helpful.
Too bad you don't want to use a locator, as robotframework has a keyword just for that:
Xpath Should Match X Times //*[contains(., "Success")] 2
The caveat is the locator should not be prepended with xpath= - just straight expression.
The library keyword Page Should Contain does pretty much exactly that, by the way.
And if you want to find how many times the string is present in the page - easy:
${count}= Get Matching Xpath Count //*[contains(., "Success")]
And then do any kind of checks on the result, e.g.
Should Be Equal ${count} 2
I thought the problem of not using locator sounds fun (the rationale behind the requirement still unclear, yet), so another solution - look in the source yourself:
${source}= Page Source # you have the whole html of the page here
${matches}= Get Regexp Matches ${source} >.*\b(Success)\b.*<
${count}= Get Length ${matches}
The first one gets the source, the second gets all non-overlapping (separate) occurrences of the target string, when it is (hopefully) inside a tag. The third line returns the count.
Disclaimer - please don't actually do that, unless you're 100% sure of the source and the structure. Use a locator.
I have a WordPress site with a form that people can fill out. The data is put into the database and used to create a simple one-page website. If the user wants to edit the website, the data is pulled out of the database and used to pre-populate the original form, where the user can change what they want and resubmit the form. The problem is that if the text entered into the form contains an apostrophe, as in "You'll love this product" when the text is read from the database and put into the value attribute for the input element, it displays in the form as "You\'ll love this product." An if that is submitted, the next time it comes back out of the database and into the form it's "You\\\'ll love this product.
How should I be handling this form text to keep these "\" escape characters from being generated and displayed?
Have you tried stripslashes(), regarding the line breaks just use the nl2br() function.
Example:
$yourString = "That\'s all\n folks";
$yourString = stripslashes(nl2br($yourString));
echo $yourString;
Note: \ double slashes will turn to \ single slashes
You should probably set-up your own function, something like:
$yourString = "That\'s all\n folks";
function escapeString($string) {
return stripslashes(nl2br($string));
}
echo escapeString($yourString);
I'm scraping a page using PHP Simple HTML DOM Parser and I want to retrieve the price. It's been going well except for a page that I've encountered, where the html reads:
<p class="was-price">Was: £220.00</p>
I want to scrape the part that reads 220.00 and I am very confused about how to retrieve it. Thus far I have been using preg_replace() with great success to strip out text from a string, yet this is the first time I have come across a currency symbol in numeric format.
Today is the first day I have used preg_replace() and it's confusing to say the least. Can it be used to remove currency symbols in this way? Or should I be looking at another method? Thanks
Use html_entity_decode() to decode encoded html entities. Then you apply preg_replace().
$str = '<p class="was-price">Was: £220.00</p>';
$str = html_entity_decode($str);
echo $str;
preg_replace(...);
How to escape multiline wordpress shortcode?
[accordion_item title="Item 2"]
item content
[/accordion_item]
We could use double brakets, but "/" sign brokes everything. Can't belive WP guys lost this case (
[[accordion_item title="Item 3"]]
item content
[[accordion_item]]
this works, but code below doesn't escaped properly
[[accordion_item title="Item 3"]]
item content
[[/accordion_item]]
Don't want to replace manually brakets with html codes. (and WP automatically get them back after user switch editor mode to visual)
Thanks in advance.
Function get_shortcode_regex() in shortcodes.php makes all logic with escaping shortcodes parsing (capture group 1 and 5)
For example with
[[new_something my_attr="test"]And have content!! [vc_tabs][/vc_tabs][/new_something]]
After preg_match_all you will get that
first capture group is not empty and it is "[" (so you can know that this shortcode is not for rendering)
second capture group will show shortcode name "new_something"
third capture group will show everything in attributes " my_attr="test""
four capture group will show content And have content!! [vc_tabs][/vc_tabs]
Five capture group will show that escape characters has at end.
Basically this means that all information is known when you write escape like this: [[your_shortcode]content[/your_shortcode]]
the Answer: replacing [ by [ and ] by ]
Link: https://wordpress.stackexchange.com/questions/33960/how-do-i-escape-a-in-a-short-code
Side Note:
Wysiwyg <=> text transition causing html encoding is, and always be a problem. I would recommend just getting rig of the visual editor all together!
I need your advice with converting plain text to an URL.
The scenario will be this: The user will select some entry and then click a "convert to link" button.
The entry text the user selected will convert to (link: selected_text). I do it with JavaScript. And after that, when he clicks the Save button to save all his entry, I don't know how to store (link: selected_text) in tha database.
The URL will be like this: www.mysite.aspx?t=selected_text.
I can convert (link: selected_text) by using replace function in code-behind. But then I don't know how to show user as clickable and also by not showing <a href="www.mysite.aspx?t=selected_text">
It can be difficult to understand therefore I will show some of my codes to explain.
Private Sub Save(ByVal Entry As String) ' Entry Comes from entry textbox '
Dim elected As String
selected = Entry.Replace("(link: ", "<a href http://www.mysite.com?link=")
selected = Entry.Replace(")", ">")
' then here starts save but not necessary to show '
End Sub
If you must save processed input for some reason
(link: here)
must be converted to
(link: here)
To store in database, you'll have to track the changes separately somehow and post them back to the server. I'd suggest a HiddenInput control.
Do not save it as www.mysite.com?t=here. Just save the entry as the user types it. While showing it to user later, convert the "(link: here)" to link and show that.
Save the post as the user wrote it. This will make it easier to allow editing of the post later. When you render the message you should use a regular expression to replace it with a real link. You should never replace all ")" with ">". What happends if i write "hello (world)"?
The result:
Hello (world>
You can find great regular expressions here:
http://regexlib.com