php preg_match value within multiple div - preg-match

I want to extract the version number of a webserver. the version number is showed on the admin login page.
i tried this:
$content = file_get_contents('URL/login.jsp');
preg_match("/<div class=\"product-version\".*div>/", $content);
echo "content: $content";
It does show the version number but also a large part of the rest of the page.
part of the page i want to have preg_match look in:
<div class="product-logo" style="background-image:url(images/product/icon-system-admin.png)">
<div class="product-version">10.3</div>
</div>
</h2>
Is this possible? or to edit the preg_match to just use the 4 characters after product-version is found?

#Toto that solved it, thanks!
Next thing is to get this working for a bunch of urls.
Want to have the script read urlcustomers.txt in the same directory and show all the version of the webserver for each customer in a table.

Related

( Laravel ) Break lines not working ; Balise aren't displayed anymore but it won't start a new line

I'm trying to break a line but it's always displayed whatever I do so I guess I'm doing something wrong.
Here is my line from my php file
But it's displayed like this :
My site is designed to help content creators on the web, create a free account and start \nmaking money now.
Can you help me please ?
Replace \n with <br>
Use <p></p>
My site is designed to help content creators on the web, create a free account and start making money now
Use CSS white-space property for \n (example)
try to use <br> on blade, and if you use {!! !!} i think that must be inner html inside your string. cmiiw
You can save your html text as variable like this
$subtitle_welcome = "<p>My site is designed to help content creators on the web, create a free account and start </p> <p> making money now.</p>";
OR
$subtitle_welcome = "My site is designed to help content creators on the web, create a free account and start <br/> making money now.";
And you have to show in blade
{!! $subtitle_welcome !!}

In voyager admin panel how to solve directory separator issue

I have created a page in the voyager admin panel, but when I tried to retrieve in view the path of the image is like
http://localhost:8000/storage/pages\October2019\eltiRUSN1BArKdXi4uyl.png
you noticed that the first forward slash and then next backward slash, so that's why an image is not displaying in view.
I used this code to print an image.
<div class="header_bg" style="background-image: url('{{ url("storage/$page_data->image") }}');"></div>
Instead of creating a url with url(), maybe you could use Laravel File Storage helpers, like Storage::get('file.jpg');. I believe these work in blade, so in your case, it would be:
<div class="header_bg" style="background-image: url('{{ Storage::get($page_data->image) }}');"></div>
The answer is, this image is set by voyage admin so I have use voyager language.
<div class="header_bg" style="background-image: url('{{Voyager::image($page_data->image)}}');"></div>
to the print image which set from voyager in blade view use this syntax
{{Voyager::image($page_data->image)}}

"Imported content is empty." error when scraping with ImportXML in GSheets

I need to scrape images' source URLs from a directory's linked web pages to columns into a Google Sheet.
I think using IMPORTXML function would be the easiest solution, but I get the #N/A "Imported content is empty." error every time.
I have tried to use this extension as well to define XPath, but still the same error.
The page's source code, where image source URL is:
<div class="centerer" id="rbt-gallery-img-1">
<i class="spinner">
<span></span>
</i>
<img data-lazy="//i.example.com/01.jpg" border="0"/>
</div>
So I want to get "i.example.com/01.jpg" value to B2, followed by further images' URLs to adjacent cells.
The function I used is:
=IMPORTXML(A2,"//img[#class='centerer']/#data-lazy")
I tried using spinner instead of centerer, with the same result.
You can get the string i.example.com/01.jpg with the following XPath-1.0 expression:
substring-after(//div[#class='centerer']/img/#data-lazy,'//')
If you don't need to remove the leading //, you can only use
//div[#class='centerer']/img/#data-lazy
So, in the first case, the Google-Sheets expression could be
=IMPORTXML(A2,"substring-after(//div[#class='centerer']/img/#data-lazy,'//')")
and in the second it could be
=IMPORTXML(A2,"//div[#class='centerer']/img/#data-lazy")

how to change html file with url get id in php

For example I have two html files sample1.html and sample2.html and I want to show them in one php file, like if I entered www.mydomain.com/index.php?show=sample1 will show the sampl1.html and ?show=sample2 will show sample2.html but in only one page
Something like that ?
<? include($_GET['show'].".html"); ?>
It not the a secure answer but I think this is what you want...

How do HtmlAgilityPack extract text from html node whose class attribute appended dynamically

Dear friends,I want to extract text 平均3.6 星 from this code segment excerpted from amazon.cn.
<div class="content"><ul>
<li><b>用户评分:</b>
<span class="crAvgStars" style="white-space:no-wrap;">
<span class="asinReviewsSummary" ref="dp_db_cm_cr_acr_pop_" name="B004GUSIKO">
<a>
<span class="swSprite s_star_3_5 " title="平均3.6 星">
<span>平均3.6 星</span>
</span>
</a>
My question is span class tag value "s_star_3_5 " vary from different customer's rating level and appended dynamically. So I attempt to use doc.DocumentNode.SelectSingleNode(" //span[#class='swSprite']").InnerText or //span[#class='swSprite s_star_3_5 '], but the result is an error or not what my want !
Any suggestions?
First of all, I suggest you saving the value of doc.DocumentNode.OuterHtml to a local .html file and see if the code you're obtaining is that code. The thing is that sometimes you start parsing a website using HtmlAgilityPack, but the very first problem is that you're not getting the valid HTML correctly. Maybe you're getting a 404 error, or a redirection, etc.
I'm suggesting this because I tested //span[#class='swSprite s_star_3_5 '] and worked correctly.
That was the issue in the following questions:
Selecting nodes that have an attribute with spaces using HTMLAgilityPack
XPath Query Problem using HTML Agility Pack
If that doesn't help, post the HTML code and I'll help you ;)
This works for me:
HtmlDocument doc = new HtmlDocument();
doc.Load(myHtml);
HtmlNode node = doc.DocumentNode.SelectSingleNode("//span[starts-with(#class, 'swSprite')]");
Console.WriteLine("Text=" + node.InnerText.Trim());
and outputs
平均3.6 星
Note I use the XPATH starts-with function.

Resources