Loading html data in Web View? - html

<p>kick 2 first look on republic day According to the latest update, the first look of the film Kick 2 will be released on 26th of January. Regular shooting of this film is going on at a brisk pace in Hyderabad. Rakul Preet is playing the female lead in this film and Thaman is scoring ...</p>
<p>The post <a rel="nofollow" href="http://www.teluguabroad.com/kick-2-first-look-republic-day/">kick 2 first look on republic day</a> appeared first on <a rel="nofollow" href="http://www.teluguabroad.com">Teluguabroad</a>.</p>
how to display this in web view and i was getting it from rss feed? to display that content in the next view controller having web view?

You need to set up a html string and then you can load this on web view.
NSString *rssString=[NSString stringWithFormat:#"<p>kick 2 first look on republic day According to the latest update, the first look of the film Kick 2 will be released on 26th of January. Regular shooting of this film is going on at a brisk pace in Hyderabad. Rakul Preet is playing the female lead in this film and Thaman is scoring ...</p><p>The post <a rel=\"nofollow\" href=\"http://www.teluguabroad.com/kick-2-first-look-republic-day/\">kick 2 first look on republic day</a> appeared first on <a rel=\"nofollow\" href=\"http://www.teluguabroad.com\">Teluguabroad</a>.</p>"];
NSString *myHTML = [NSString stringWithFormat:#"<html><body>%#</body></html>",rssString];
[myUIWebView loadHTMLString:myHTML baseURL:nil];
Also notice that for every double quotes " used in NSString we have appended a single slash'\'. So that Xcode compiler can understand that these double quotes are a part of string and will not confuse NSString with #" " identifier which we use in Xcode.
And in case you need to load this to next view controller, you can send the string myHTMl to next view controller using property and load on web view .

Related

Extract Image url from WordPress REST API JSON response

I'm new to WordPress REST API and I don't know how to extract the image URLs from the "content" key of the API (https://www.example.com/wp-json/wp/v2/posts) response which looks like this:
"content": {
"rendered": "\n<p>From munching on a casual pizza to romantic candlelit dinner in Kolkata with your better half, Valentine’s week is filled with all of these!</p>\n\n\n\n<p>The love week of February offers the perfect excuse to sample Kolkata’s very best restaurants with your other half.</p>\n\n\n\n<p>Find your dream date night in our Valentine’s Day special guide to the cutest restaurants in Kolkata.</p>\n\n\n\n<h2><i><center>Blue and Beyond</center></i></h2>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img src=\"https://kolkatasutra.com/wp-content/uploads/2021/02/blue-n-beyond.png\" alt=\"\" class=\"wp-image-919\" srcset=\"https://kolkatasutra.com/wp-content/uploads/2021/02/blue-n-beyond.png 540w, https://kolkatasutra.com/wp-content/uploads/2021/02/blue-n-beyond-300x197.png 300w, https://kolkatasutra.com/wp-content/uploads/2021/02/blue-n-beyond-150x99.png 150w\" sizes=\"(max-width: 540px) 100vw, 540px\" /><figcaption>Blue & Beyond, New Market</figcaption></figure></div>\n\n\n\n<p>Situated in the New Market area, this place boasts of beautiful rooftop open-air seating. It also has an indoor seating</p>\n\n\n\n<p>You can expect a feel of colonial Kolkata with Stuart Hogg Market below."
}
I tried this solution, but the "featured_media" is 0 in my case.
Installed this plugin, but the field "better_featured_image" is showing as null in all the posts.
This is the only solution that might solve the problem, but I don't know how to extract Image URLs using Regex.
Please help me with the Regex to extract the URLs. Or if there's another way which might help, please mention in the ans.
You can decode json string usgin json_decode() fucntion. then you can preg_match to match with '/src="([^"]*)"/' regex that extract your src. check below code.
<?php
$image = '{"content": {"rendered": "\n<p>From munching on a casual pizza to romantic candlelit dinner in Kolkata with your better half, Valentine’s week is filled with all of these!</p>\n\n\n\n<p>The love week of February offers the perfect excuse to sample Kolkata’s very best restaurants with your other half.</p>\n\n\n\n<p>Find your dream date night in our Valentine’s Day special guide to the cutest restaurants in Kolkata.</p>\n\n\n\n<h2><i><center>Blue and Beyond</center></i></h2>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img src=\"https://kolkatasutra.com/wp-content/uploads/2021/02/blue-n-beyond.png\" alt=\"\" class=\"wp-image-919\" srcset=\"https://kolkatasutra.com/wp-content/uploads/2021/02/blue-n-beyond.png 540w, https://kolkatasutra.com/wp-content/uploads/2021/02/blue-n-beyond-300x197.png 300w, https://kolkatasutra.com/wp-content/uploads/2021/02/blue-n-beyond-150x99.png 150w\" sizes=\"(max-width: 540px) 100vw, 540px\" /><figcaption>Blue & Beyond, New Market</figcaption></figure></div>\n\n\n\n<p>Situated in the New Market area, this place boasts of beautiful rooftop open-air seating. It also has an indoor seating</p>\n\n\n\n<p>You can expect a feel of colonial Kolkata with Stuart Hogg Market below."}}';
$image = json_decode($image, true);
preg_match('/src="([^"]*)"/',$image['content']['rendered'], $result);
echo $result[1]; die;
?>

Insert a header from a HTML into VB

I am currently doing a school project for an elite program that serves every user's aviation purposes, from customers to pilots. I wanted to grab a text from a website called Fuel Planner. The user will input their departure and destination and then the website will load how much fuel is needed for that flight. However, I only need one part of that HTML which is the part where it prints the amount of fuel needed. The HTML code for that is as shown below:
<!-- end #menu -->
<div id="about">
<h3>Airbus A300-600-PW4158 Fuel Planner</h3>
<p>Sydney to Brisbane YSSY-YBBN (406 NM)<br></p>
<h2>Total Fuel: 26608 POUNDS</h2>
The line that I need to grab is
<h2>Total Fuel: 26608 POUNDS</h2>
I want this line to be inserted into the textbox txtFOB.Text.
Both are on the same form but on different tabs, so we don't have to worry about that. The web browser is called webFuel in the form frmPilots.
For this example, the departure ORIG is going to be
YSSY (Sydney)
And the arrival DEST will be
YBBN (Brisbane)
And the aircraft would be
A300-600
Both can be inserted into the two text boxes on the website's home page. Any help would be greatly appreciated. Thanks!
Since the element doesn't have an ID, you would need to loop thru the elements collection and look for the element you are interested in.
Try the following:
For Each element As HtmlElement In webFuel.Document.GetElementsByTagName("H2")
If element.InnerText Like "Total Fuel: * POUNDS" Then
'this is the element we are looking for...
txtFOB.Text = element.InnerText.Replace("Total Fuel:","").Replace("POUNDS","").Trim()
Exit For
End If
Next
NB: You have put a lot of tags in the question which is confusing. The above code is for VB.NET and is not tested.

how to display data in html

In my project, I am retrieving an address from the database and displaying this address on page. The issue or problem that I am facing is the the way the retrieved address is being displayed.
Basically this is the way the address is being displayed:
Address: 1 Kings Street Kilmarnock East Berkshire Scotland KA1 UIT
I would like the address to be displayed like so:
Address: 1 Kings Street
Kilmarnock
East Berkshire
Scotland
KA1 UIT
How can I do this in HTML or css? I am currently using twitter bootstrap , and I don't if there is anyway to do using it.
Oh.. It's hard but let me try... ;)
<div>Address: 1 Kings Street<br> Kilmarnock <br>East Berkshire<br> Scotland <br>KA1 UIT</div>
Your Expected Output:
Address: 1 Kings Street
Kilmarnock
East Berkshire
Scotland
KA1 UIT
Working Demo
Note: This is just simplest and basic way.. But if Data is coming from any database dynamically then at-least you should explain in details from where it comes and by which object it can be accessible.. Then you can apply JS or regex functions... I hope you understand what I mean..
If you edited the data in your database, and used a comma between each line, you might be able to split the data. (your question doesn't state what language you are writing in (mvc/how data is being received).
However, once you have the string, you can use the String.split method (available in most languages), and hence could adapt your view accordingly.
So,
Address: 1 Kings Street, Kilmarnock, East Berkshire, Scotland, KA1 UIT
would become
{1 Kings Street}{ Kilmarnock}{ East Berkshire}{ Scotland}{ KA1 UIT}
which you could then do a foreach block, displaying them onto the screen as you requested
A possible alternative (although probably not easy), would be to extract the postcode, and call a google maps API call to receive the address - but again, this would be quite difficult.
At present, I cannot see how you would be able to expect a program to decide where to split the address into separate lines (unless you place them into different fields which was described in the comments).
You can add <p> to each line, or put <br> at the end of each lines.
But
If your retrieving the data from a database through a php variable you cannot do that with pure html / css, you'll need string manipulation with PHP.

UITextView: Replace Special Characters [duplicate]

in xml data is
<content_special>
SAT 17TH TEST test club cheap drinks £3 shots £5 bottles $beers
</content_special>
i get this string using this code
TBXMLElement *Content_Special=[TBXML childElementNamed:#"content_special" parentElement:Club];
NSString *Content_SpecialStr = [TBXML textForElement:Content_Special];
when i NSLog(#"Content_special:%#",Content_SpecialStr);
that print like this
Content_special:SAT 17TH TEST
test club
cheap drinks
£3 shots
£5 bottles
$beers
how can i get original sting which Display in Xlm ? Any suggestion...
Found Solution Using Google Toolbox for Mac GTMNSString+HTML.h ,GTMNSString+HTML.m And GTMDefines.h,
First #import "GTMNSString+HTML.h"
use like This: Content_SpecialStr = [Content_SpecialStr gtm_stringByUnescapingFromHTML];
Ensure your data xml file has utf-8 encoding http://www.w3schools.com/xml/xml_encoding.asp

Select all text before <br>

I have the following awful HTML:
<p>
102036 - <em>In re</em> State v. Williams video<br>
104236 - University of Kansas Hosp. Auth. v. Board of Wabaunsee County Comm'rs video
</p>
I want to use XPath to capture all of the text following each </a>, so:
Item 1: " - In re State v. Williams
Item 2: " - University of Kansas Hosp. Auth. v. Board of Wabunsee County
Alternatively, I could just capture all text, and that would be fine too:
Item 1: "102036 - In re State v. Williams
Item 2: "104236 - University of Kansas Hosp. Auth. v. Board of Wabunsee County
I've been trying various things for a while now, but making no progress. I want something like:
/a/following::text()[before::br]
Help?
Here you go, pal:
//a//following-sibling::text() | //a//following-sibling::*[not(self::a)]/text()
The best thing I've found so far is to simply nuke the errant <em> nodes.
So:
elem = html.xpath('//p')[0]
etree.strip_tags(elem, 'em')
Then, using the cleaner html, a simple XPath can be used:
texts = [e.tail for e in elem.xpath('//a')]
Credit where due: https://stackoverflow.com/a/8788559/64911
If you have firebug installed and are running Firefox, for this and all future xpath needs you can just follow this tutorial:
http://www.wikihow.com/Find-XPath-Using-Firebug
Very easy way to find the xpath for anything on a page.