Beginners – Generate a daily sitemap and update using a URL string

Code review

I wrote method generate sitemapwhich is part of a big class, update Stocks, It creates a daily sitemap and can refresh it several times a day.

generate sitemap has an input string and is called within a for loop, much like:

{Pseudocode} for i = 1 to 8000;
Input received[i]; // for example: & # 39; aapl-apple-technology-nasdaq-us-8f4c & # 39;
UpdateStocks :: generateSitemap (input[i]);
{/ pseudocode} endfor;

Would you be so nice and repeat it to me and help me make it faster, easier or more efficient?

generate sitemap

        / **
*
* @return to return a large string in a txt file containing all the URLs for a daily sitemap
* /
public static function generateSitemap ($ lurl) {
$ dir = __ DIR__. self :: DIR_FRONT_PUBLIC_HTML;

// url
$ sm = sprintf (& # 39;% s% s% s & # 39;
self :: PROTOCOL.self :: DOMAIN.self :: SLASH.self :: DIR_URL_KEYWORD_1.self :: SLASH.self :: DIR_URL_KEYWORD_2.self :: SLASH,
$ lurl,
self :: NEW_LINE
);
$ dt = new  DateTime (& # 39; now & # 39;);
$ dt = $ dt-> format (& # 39; Y-m-d & # 39;); // today
$ fn = $ you. self :: SITEMAP_PREFIX. $ dt self :: EXTENSION_TXT; // sitemap filename in public_html

// if the daily sitemap already exists
if (file_exists ($ fn)) {
$ arr = preg_split (& # 39; /  n / & # 39 ;, trim (file_get_contents ($ fn))); // array of links
$ i = 0; // Counter
foreach ($ arr as $ k => $ lk) {
if ($ arr[$k]== null) {unset ($ arr[$k])}
if (trim ($ lk) === trim ($ sm)) {// link already exists
$ i ++;
if ($ i> 0) {$ arr[$k]= null;} // Link already exists several times
}otherwise{
if ($ k == sizeof ($ arr) -1) {
$ k ++;
$ arr[$k]= $ sm;
$ arr = implode (self :: NEW_LINE, $ arr);
$ fh = fopen ($ fn, & bgr; wb & # 39;);
fwrite ($ fh, $ arr);
fclose ($ fh);
}
continue;
}
}
}otherwise{
$ fh = fopen ($ fn, & bgr; wb & # 39;);
fwrite ($ fh, $ sm);
fclose ($ fh);
}
}

Example of inputs

a-agilent-technologies-healthcare-nyse-us-39d4
aa-Alcoa-based materials-nyse-us-159a
AAAU-perth-mint-physical-gold-nyse-us-8ed9
aaba-Altaba-financial-services-nasdaq-us-26f5
aac-healthcare-nyse-us-e92a
aadr-advisor shares-dorsey-wright-adr-nyse-us-d842
aal-airline industrials-nasdaq-us-29eb
AAMC-Altisource-asset-management-de-financial-services-nyse-us-b46a
aan-aaron-industrials-nyse-us-d00e
aaoi-applied optoelectronics technology nasdaq-us-1dee
AAON-basic-materials-nasdaq-us-238e
aap-advance-auto-parts-wi-consumer cyclical-nyse-us-1f60
AAPL-apple-technology-nasdaq-us-8f4c
aat-assets-real-estate-nyse-us-3598
aau-almaden-minerals-basic materials-nyse-us-1c57
AAWW-atlas-air world-industrials-nasdaq-us-69f3
aaxj-iShares MSCI-all-country Asia-ex-japan-nasdaq-us-c6c4
aaxn-axon-enterprise-industrials-nasdaq-us-0eef
from-alliance amber-units-financial-services-nyse-us-DEB1
abac-renmin-tianli-consumer-defensive-nasdaq-us-8701
fig-industrials-nyse-us-A407
ABBV-AbbVie-healthcare-nyse-us-9aea
abc-AmerisourceBergen-healthcare-nyse-us-bd9d
abcb-ameris Bancorp-financial-services-nasdaq-us-DF98
abdc-alcentra-capital-financial-services-nasdaq-us-96dd
abeo-Abeona-therapeutics-healthcare-nasdaq-us-aa0f
abeow-market-us-d84d
abev-AmBev-1-consumer-defensive-NYSE-us-a9b4
abg asbury-automotive-consumer-cyclic-nyse-us-db5f
abil-capacity technology-nasdaq-us-91a6
abio-Arca biopharma-healthcare-nasdaq-us-098e
abm-abm-industries-industrials-nyse-us-bcbc
ARMD-Abiomed-healthcare-nasdaq-us-2818
abr-arbor real estate real estate-nyse-us-68b1
abr-a-arbor real estate real estate-nyse-us-8c1d
abr-b-arbor-property-property-NYSE-us-97f2
abr-c-arbor-property-property-NYSE-us-ee81
abt-abbott laboratories-healthcare-nyse-us-c7fd
abtx-allegiance-Bancshares-financial-services-nasdaq-us-6913
abus-arbutus-biopharma-healthcare-nasdaq-us-C23F
AC associated capital-financial services-nyse-us-FCA3
aca-arcosa-industrials-nyse-us-B429

Part of sitemap-2019-03-15.txt:

domain.org/url[0]/ url[1]/ a-agilent-technologies-healthcare-nyse-us-39d4
domain.org/url[0]/ url[1]/ aa-alcoa-base-materials-nyse-us-159a
domain.org/url[0]/ url[1]/ aaau-perth-mint-physical-gold-nyse-us-8ed9
domain.org/url[0]/ url[1]/aba-altaba-financial-services-nasdaq-us-26f5
domain.org/url[0]/ url[1]/ aac-healthcare-nyse-us-e92a
domain.org/url[0]/ url[1]/ aadr-advisorshares-dorsey-wright-adr-nyse-us-d842
domain.org/url[0]/ url[1]/ aal-airline-industrials-nasdaq-us-29eb
domain.org/url[0]/ url[1]/ aamc-altisource-asset-management-com-financial-services-nyse-us-b46a
domain.org/url[0]/ url[1]/ aan-aarons-industrials-nyse-us-d00e
domain.org/url[0]/ url[1]/ aaoi-applied optoelectronics nasdaq-us-1dee
domain.org/url[0]/ url[1]/ aaon-basic-materials-nasdaq-us-238e
domain.org/url[0]/ url[1]/ aap-advance-auto-parts-wi-consumer-cyclical-nyse-us-1f60
domain.org/url[0]/ url[1]/ aapl-apple-technology-nasdaq-us-8f4c
domain.org/url[0]/ url[1]/ aat-assets-real-estate-nyse-us-3598
domain.org/url[0]/ url[1]/ aau-almaden-minerals-bases-nyse-us-1c57
domain.org/url[0]/ url[1]/ aaww-atlas-air-world-industrial-nasdaq-us-69f3
domain.org/url[0]/ url[1]/ aaxj-ishares-msci-all-country-asia-ex-japan-nasdaq-us-c6c4
domain.org/url[0]/ url[1]/ aaxn-axon-enterprise-industrial-nasdaq-us-0eef
domain.org/url[0]/ url[1]/ ab-alliance amber-units-financial-services-nyse-us-deb1
domain.org/url[0]/ url[1]/ abac-renmin-tianli-consumer-defensive-nasdaq-us-8701
domain.org/url[0]/ url[1]/ abb-industrial-nyse-us-a407
domain.org/url[0]/ url[1]/ abbv-abbvie-healthcare-nyse-us-9aea
domain.org/url[0]/ url[1]/ abc-amerisourcebergen-healthcare-nyse-us-bd9d
domain.org/url[0]/ url[1]/ abcb-ameris-bancorp-financial-services-nasdaq-us-df98
domain.org/url[0]/ url[1]/ abdc-alcentra-capital-financial-services-nasdaq-us-96dd
domain.org/url[0]/ url[1]/ abeo-abeona-therapeutics-healthcare-nasdaq-us-aa0f
domain.org/url[0]/ url[1]/ abeow-market-us-d84d
domain.org/url[0]/ url[1]/ abev-ambev-1-consumer-defensive-nyse-us-a9b4
domain.org/url[0]/ url[1]/ abg-asbury-automotive-consumer-cyclic-nyse-us-db5f
domain.org/url[0]/ url[1]/ abil-capability-technology-nasdaq-us-91a6
domain.org/url[0]/ url[1]/ abio-arca-biopharma-healthcare-nasdaq-us-098e
domain.org/url[0]/ url[1]/ abm-abm-industries-industrials-nyse-us-bcbc
domain.org/url[0]/ url[1]/ abmd-abiomed-healthcare-nasdaq-us-2818
domain.org/url[0]/ url[1]/ abr-arbor-real estate-property-nyse-us-68b1
domain.org/url[0]/ url[1]/ abr-a-arbor-real estate-real estate-nyse-us-8c1d
domain.org/url[0]/ url[1]/ abr-b-arbor-real estate-real estate-nyse-us-97f2
domain.org/url[0]/ url[1]/ abr-c-arbor-real estate-real estate-nyse-us-ee81
domain.org/url[0]/ url[1]/ abt-abbott-laboratories-healthcare-nyse-us-c7fd
domain.org/url[0]/ url[1]/ abtx-allegiance-bancshares-financial-services-nasdaq-us-6913
domain.org/url[0]/ url[1]/ abus-arbutus-biopharma-healthcare-nasdaq-us-c23f
domain.org/url[0]/ url[1]/ ac associated-capital-financial-services-nyse-us-fca3
domain.org/url[0]/ url[1]/ aca-arcosa-industrials-nyse-us-b429

Issue with sitemap

hi Guys

My Sitemap was not recently indexed by Google. When I try to get my sitemap, I get the following error:

"& # 39; noindex & # 39; has noted i … Read the rest of http://www.webhostingtalk.com/showthread.php?t=1756407&goto=newpost

What is Sitemap? | Proxies-free

Talk in & # 39; White Hat SEO & # 39; started by Aradya, March 13, 2019 at 12:54 pm,

keywords:

  • seo
  1. Ar

    Aradya
    New member


    • member

    joined:
    18th of July 2018
    Messages:
    3
    Likes received:
    0
    Trophy Points:
    1

    What is Sitemap? What is the difference when adding a sitemap to a website? If it's a must on a website, what kind of Sitemap do we need to use?

    Mobile App Development Hyderabad | Android Apps Development Pune


    Aradya,
    March 13, 2019 at 12:54 pm

    # 1

Share this page

google – I have encountered a problem with my Sitemap

My question is about my previous question on how to effectively remove indexed pages from Google. I was recommended to create an XML sitemap and send it to Google. The council looked solid, so I created one.

When I created my custom sitemap and submitted it to google, it did not select a URL and basically every URL has an error. I've replaced &, & 39 ;, & quot; (spaces) and other characters to properly encode all links, but I'm still getting the error, I've checked my third-party sitemap (xml-sitemap) and it has not been an error I want to know what I'm doing wrong

Enter the image description here

Enter the image description here

Here is the sitemap section







www.peshawar.co/search.php?keywords=&city=peshawar

2019-03-10
weekly
0.8






www.peshawar.co/search.php?keywords=17%20Anfrage&city=peshawar

2019-03-10
weekly
0.8






www.peshawar.co/search.php?keywords=3D%20Printers&city=peshawar

2019-03-10
weekly
0.8

Here is the actual sitemap that contains 34K links and takes a download. Could it be the size of XML that causes the problem? (Very unlikely)

Does your robots.txt file contain sitemap references?

The only real time needed for sitemaps is for very complex sites where indexing bots may not find important pages on time.

I never considered a sitemap for my site until I had over 9,000 pages and NEVER had a problem indexing. If managing sitemaps was not that easy, I probably would not have a sitemap on my site today, even though I currently have over 13,000 pages.

Before and after the comparison I see NO difference in how my site is indexed and where it ends up in the SERPS.

URL – WWW version of the site is missing in the sitemap

I switched from Blogger to WordPress 5 months ago, and my URL structure changed from https://example.com to https://www.example.com

The WWW was added manually.

I currently have 94 articles on my website after I deleted over 400 when I switched the lifestyle niche to books. But suddenly Google 22k indexes URLs and bling it at 7k. With the help of a webmaster here I have found that many of these URLs consist of the www and non-www version of my website.

However, when I checked in my robot text, I found that my Sitemap URL was included in the non-WWW version.

There seems to be a huge problem on this site that I do not see, and it causes a stir on Google and Bing Bots.

Can someone help please?