Generate a Daily Sitemap and Update using a URL String InputRemove parameters from string containing URLUpdate URL with new parameter valueJava class that generates a short URL string for an input stringURL link SEO and security using LaravelRead and replace URL from PDF fileParsing URL query and appending it at end of the other URLRecreating a URL stringRemove a query string parameter from a URLError handling with C-string input using get() and getline()Splitting URL query string to key-value pairs
What are substitutions for coconut in curry?
Why Choose Less Effective Armour Types?
Look at your watch and tell me what time is it. vs Look at your watch and tell me what time it is
Credit cards used everywhere in Singapore or Malaysia?
Gravity magic - How does it work?
How can I track script which gives me "command not found" right after the login?
What approach do we need to follow for projects without a test environment?
Why doesn't the EU now just force the UK to choose between referendum and no-deal?
SOQL: Populate a Literal List in WHERE IN Clause
Knife as defense against stray dogs
Why would a flight no longer considered airworthy be redirected like this?
Co-worker team leader wants to inject his friend's awful software into our development. What should I say to our common boss?
Are all passive ability checks floors for active ability checks?
Does Mathematica reuse previous computations?
How to write cleanly even if my character uses expletive language?
How to change two letters closest to a string and one letter immediately after a string using notepad++
In a future war, an old lady is trying to raise a boy but one of the weapons has made everyone deaf
Identifying the interval from A♭ to D♯
Do the common programs (for example: "ls", "cat") in Linux and BSD come from the same source code?
Instead of Universal Basic Income, why not Universal Basic NEEDS?
Most cost effective thermostat setting: consistent temperature vs. lowest temperature possible
Welcoming 2019 Pi day: How to draw the letter π?
Is a party consisting of only a bard, a cleric, and a warlock functional long-term?
Do I need to be arrogant to get ahead?
Generate a Daily Sitemap and Update using a URL String Input
Remove parameters from string containing URLUpdate URL with new parameter valueJava class that generates a short URL string for an input stringURL link SEO and security using LaravelRead and replace URL from PDF fileParsing URL query and appending it at end of the other URLRecreating a URL stringRemove a query string parameter from a URLError handling with C-string input using get() and getline()Splitting URL query string to key-value pairs
$begingroup$
Code Review
I wrote method generateSitemap
, which is part of a large class, UpdateStocks
. It generates a daily sitemap and can update it few times a day.
generateSitemap
has an input string and called inside a for loop, similar to:
pseudocode for i=1 to 8000;
get input[i]; // for example: 'aapl-apple-technology-nasdaq-us-8f4c'
UpdateStocks::generateSitemap(input[i]);
/pseudocode endfor;
Would you be so kind and review it and help me to possibly make it faster, simpler or more efficient?
generateSitemap
/**
*
* @return a large string in a txt file including all urls for a daily sitemap
*/
public static function generateSitemap($lurl)
$dir=__DIR__ . self::DIR_FRONT_PUBLIC_HTML;
// url
$sm=sprintf('%s%s%s',
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('now');
$dt=$dt->format('Y-m-d'); // today
$fn=$dir . self::SITEMAP_PREFIX . $dt . self::EXTENSION_TXT; // sitemap filename in public_html
// if daily sitemap already exits
if(file_exists($fn))
$arr = preg_split('/n/', 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 exist
$i++;
if($i>0)$arr[$k]=null; // link already exist more than once
else
if($k==sizeof($arr)-1)
$k++;
$arr[$k]=$sm;
$arr=implode(self::NEW_LINE, $arr);
$fh=fopen($fn, 'wb');
fwrite($fh, $arr);
fclose($fh);
continue;
else
$fh=fopen($fn, 'wb');
fwrite($fh, $sm);
fclose($fh);
Example of Inputs
a-agilent-technologies-healthcare-nyse-us-39d4
aa-alcoa-basic-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-advisorshares-dorsey-wright-adr-nyse-us-d842
aal-airlines-industrials-nasdaq-us-29eb
aamc-altisource-asset-management-com-financial-services-nyse-us-b46a
aan-aarons-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-worldwide-industrials-nasdaq-us-69f3
aaxj-ishares-msci-all-country-asia-ex-japan-nasdaq-us-c6c4
aaxn-axon-enterprise-industrials-nasdaq-us-0eef
ab-alliancebernstein-units-financial-services-nyse-us-deb1
abac-renmin-tianli-consumer-defensive-nasdaq-us-8701
abb-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-cyclical-nyse-us-db5f
abil-ability-technology-nasdaq-us-91a6
abio-arca-biopharma-healthcare-nasdaq-us-098e
abm-abm-industries-industrials-nyse-us-bcbc
abmd-abiomed-healthcare-nasdaq-us-2818
abr-arbor-realty-real-estate-nyse-us-68b1
abr-a-arbor-realty-real-estate-nyse-us-8c1d
abr-b-arbor-realty-real-estate-nyse-us-97f2
abr-c-arbor-realty-real-estate-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-basic-materials-nyse-us-159a
domain.org/url[0]/url[1]/aaau-perth-mint-physical-gold-nyse-us-8ed9
domain.org/url[0]/url[1]/aaba-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-airlines-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-technology-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-basic-materials-nyse-us-1c57
domain.org/url[0]/url[1]/aaww-atlas-air-worldwide-industrials-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-industrials-nasdaq-us-0eef
domain.org/url[0]/url[1]/ab-alliancebernstein-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-industrials-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-cyclical-nyse-us-db5f
domain.org/url[0]/url[1]/abil-ability-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-realty-real-estate-nyse-us-68b1
domain.org/url[0]/url[1]/abr-a-arbor-realty-real-estate-nyse-us-8c1d
domain.org/url[0]/url[1]/abr-b-arbor-realty-real-estate-nyse-us-97f2
domain.org/url[0]/url[1]/abr-c-arbor-realty-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
beginner php algorithm strings url
$endgroup$
add a comment |
$begingroup$
Code Review
I wrote method generateSitemap
, which is part of a large class, UpdateStocks
. It generates a daily sitemap and can update it few times a day.
generateSitemap
has an input string and called inside a for loop, similar to:
pseudocode for i=1 to 8000;
get input[i]; // for example: 'aapl-apple-technology-nasdaq-us-8f4c'
UpdateStocks::generateSitemap(input[i]);
/pseudocode endfor;
Would you be so kind and review it and help me to possibly make it faster, simpler or more efficient?
generateSitemap
/**
*
* @return a large string in a txt file including all urls for a daily sitemap
*/
public static function generateSitemap($lurl)
$dir=__DIR__ . self::DIR_FRONT_PUBLIC_HTML;
// url
$sm=sprintf('%s%s%s',
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('now');
$dt=$dt->format('Y-m-d'); // today
$fn=$dir . self::SITEMAP_PREFIX . $dt . self::EXTENSION_TXT; // sitemap filename in public_html
// if daily sitemap already exits
if(file_exists($fn))
$arr = preg_split('/n/', 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 exist
$i++;
if($i>0)$arr[$k]=null; // link already exist more than once
else
if($k==sizeof($arr)-1)
$k++;
$arr[$k]=$sm;
$arr=implode(self::NEW_LINE, $arr);
$fh=fopen($fn, 'wb');
fwrite($fh, $arr);
fclose($fh);
continue;
else
$fh=fopen($fn, 'wb');
fwrite($fh, $sm);
fclose($fh);
Example of Inputs
a-agilent-technologies-healthcare-nyse-us-39d4
aa-alcoa-basic-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-advisorshares-dorsey-wright-adr-nyse-us-d842
aal-airlines-industrials-nasdaq-us-29eb
aamc-altisource-asset-management-com-financial-services-nyse-us-b46a
aan-aarons-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-worldwide-industrials-nasdaq-us-69f3
aaxj-ishares-msci-all-country-asia-ex-japan-nasdaq-us-c6c4
aaxn-axon-enterprise-industrials-nasdaq-us-0eef
ab-alliancebernstein-units-financial-services-nyse-us-deb1
abac-renmin-tianli-consumer-defensive-nasdaq-us-8701
abb-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-cyclical-nyse-us-db5f
abil-ability-technology-nasdaq-us-91a6
abio-arca-biopharma-healthcare-nasdaq-us-098e
abm-abm-industries-industrials-nyse-us-bcbc
abmd-abiomed-healthcare-nasdaq-us-2818
abr-arbor-realty-real-estate-nyse-us-68b1
abr-a-arbor-realty-real-estate-nyse-us-8c1d
abr-b-arbor-realty-real-estate-nyse-us-97f2
abr-c-arbor-realty-real-estate-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-basic-materials-nyse-us-159a
domain.org/url[0]/url[1]/aaau-perth-mint-physical-gold-nyse-us-8ed9
domain.org/url[0]/url[1]/aaba-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-airlines-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-technology-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-basic-materials-nyse-us-1c57
domain.org/url[0]/url[1]/aaww-atlas-air-worldwide-industrials-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-industrials-nasdaq-us-0eef
domain.org/url[0]/url[1]/ab-alliancebernstein-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-industrials-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-cyclical-nyse-us-db5f
domain.org/url[0]/url[1]/abil-ability-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-realty-real-estate-nyse-us-68b1
domain.org/url[0]/url[1]/abr-a-arbor-realty-real-estate-nyse-us-8c1d
domain.org/url[0]/url[1]/abr-b-arbor-realty-real-estate-nyse-us-97f2
domain.org/url[0]/url[1]/abr-c-arbor-realty-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
beginner php algorithm strings url
$endgroup$
add a comment |
$begingroup$
Code Review
I wrote method generateSitemap
, which is part of a large class, UpdateStocks
. It generates a daily sitemap and can update it few times a day.
generateSitemap
has an input string and called inside a for loop, similar to:
pseudocode for i=1 to 8000;
get input[i]; // for example: 'aapl-apple-technology-nasdaq-us-8f4c'
UpdateStocks::generateSitemap(input[i]);
/pseudocode endfor;
Would you be so kind and review it and help me to possibly make it faster, simpler or more efficient?
generateSitemap
/**
*
* @return a large string in a txt file including all urls for a daily sitemap
*/
public static function generateSitemap($lurl)
$dir=__DIR__ . self::DIR_FRONT_PUBLIC_HTML;
// url
$sm=sprintf('%s%s%s',
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('now');
$dt=$dt->format('Y-m-d'); // today
$fn=$dir . self::SITEMAP_PREFIX . $dt . self::EXTENSION_TXT; // sitemap filename in public_html
// if daily sitemap already exits
if(file_exists($fn))
$arr = preg_split('/n/', 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 exist
$i++;
if($i>0)$arr[$k]=null; // link already exist more than once
else
if($k==sizeof($arr)-1)
$k++;
$arr[$k]=$sm;
$arr=implode(self::NEW_LINE, $arr);
$fh=fopen($fn, 'wb');
fwrite($fh, $arr);
fclose($fh);
continue;
else
$fh=fopen($fn, 'wb');
fwrite($fh, $sm);
fclose($fh);
Example of Inputs
a-agilent-technologies-healthcare-nyse-us-39d4
aa-alcoa-basic-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-advisorshares-dorsey-wright-adr-nyse-us-d842
aal-airlines-industrials-nasdaq-us-29eb
aamc-altisource-asset-management-com-financial-services-nyse-us-b46a
aan-aarons-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-worldwide-industrials-nasdaq-us-69f3
aaxj-ishares-msci-all-country-asia-ex-japan-nasdaq-us-c6c4
aaxn-axon-enterprise-industrials-nasdaq-us-0eef
ab-alliancebernstein-units-financial-services-nyse-us-deb1
abac-renmin-tianli-consumer-defensive-nasdaq-us-8701
abb-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-cyclical-nyse-us-db5f
abil-ability-technology-nasdaq-us-91a6
abio-arca-biopharma-healthcare-nasdaq-us-098e
abm-abm-industries-industrials-nyse-us-bcbc
abmd-abiomed-healthcare-nasdaq-us-2818
abr-arbor-realty-real-estate-nyse-us-68b1
abr-a-arbor-realty-real-estate-nyse-us-8c1d
abr-b-arbor-realty-real-estate-nyse-us-97f2
abr-c-arbor-realty-real-estate-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-basic-materials-nyse-us-159a
domain.org/url[0]/url[1]/aaau-perth-mint-physical-gold-nyse-us-8ed9
domain.org/url[0]/url[1]/aaba-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-airlines-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-technology-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-basic-materials-nyse-us-1c57
domain.org/url[0]/url[1]/aaww-atlas-air-worldwide-industrials-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-industrials-nasdaq-us-0eef
domain.org/url[0]/url[1]/ab-alliancebernstein-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-industrials-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-cyclical-nyse-us-db5f
domain.org/url[0]/url[1]/abil-ability-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-realty-real-estate-nyse-us-68b1
domain.org/url[0]/url[1]/abr-a-arbor-realty-real-estate-nyse-us-8c1d
domain.org/url[0]/url[1]/abr-b-arbor-realty-real-estate-nyse-us-97f2
domain.org/url[0]/url[1]/abr-c-arbor-realty-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
beginner php algorithm strings url
$endgroup$
Code Review
I wrote method generateSitemap
, which is part of a large class, UpdateStocks
. It generates a daily sitemap and can update it few times a day.
generateSitemap
has an input string and called inside a for loop, similar to:
pseudocode for i=1 to 8000;
get input[i]; // for example: 'aapl-apple-technology-nasdaq-us-8f4c'
UpdateStocks::generateSitemap(input[i]);
/pseudocode endfor;
Would you be so kind and review it and help me to possibly make it faster, simpler or more efficient?
generateSitemap
/**
*
* @return a large string in a txt file including all urls for a daily sitemap
*/
public static function generateSitemap($lurl)
$dir=__DIR__ . self::DIR_FRONT_PUBLIC_HTML;
// url
$sm=sprintf('%s%s%s',
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('now');
$dt=$dt->format('Y-m-d'); // today
$fn=$dir . self::SITEMAP_PREFIX . $dt . self::EXTENSION_TXT; // sitemap filename in public_html
// if daily sitemap already exits
if(file_exists($fn))
$arr = preg_split('/n/', 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 exist
$i++;
if($i>0)$arr[$k]=null; // link already exist more than once
else
if($k==sizeof($arr)-1)
$k++;
$arr[$k]=$sm;
$arr=implode(self::NEW_LINE, $arr);
$fh=fopen($fn, 'wb');
fwrite($fh, $arr);
fclose($fh);
continue;
else
$fh=fopen($fn, 'wb');
fwrite($fh, $sm);
fclose($fh);
Example of Inputs
a-agilent-technologies-healthcare-nyse-us-39d4
aa-alcoa-basic-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-advisorshares-dorsey-wright-adr-nyse-us-d842
aal-airlines-industrials-nasdaq-us-29eb
aamc-altisource-asset-management-com-financial-services-nyse-us-b46a
aan-aarons-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-worldwide-industrials-nasdaq-us-69f3
aaxj-ishares-msci-all-country-asia-ex-japan-nasdaq-us-c6c4
aaxn-axon-enterprise-industrials-nasdaq-us-0eef
ab-alliancebernstein-units-financial-services-nyse-us-deb1
abac-renmin-tianli-consumer-defensive-nasdaq-us-8701
abb-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-cyclical-nyse-us-db5f
abil-ability-technology-nasdaq-us-91a6
abio-arca-biopharma-healthcare-nasdaq-us-098e
abm-abm-industries-industrials-nyse-us-bcbc
abmd-abiomed-healthcare-nasdaq-us-2818
abr-arbor-realty-real-estate-nyse-us-68b1
abr-a-arbor-realty-real-estate-nyse-us-8c1d
abr-b-arbor-realty-real-estate-nyse-us-97f2
abr-c-arbor-realty-real-estate-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-basic-materials-nyse-us-159a
domain.org/url[0]/url[1]/aaau-perth-mint-physical-gold-nyse-us-8ed9
domain.org/url[0]/url[1]/aaba-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-airlines-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-technology-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-basic-materials-nyse-us-1c57
domain.org/url[0]/url[1]/aaww-atlas-air-worldwide-industrials-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-industrials-nasdaq-us-0eef
domain.org/url[0]/url[1]/ab-alliancebernstein-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-industrials-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-cyclical-nyse-us-db5f
domain.org/url[0]/url[1]/abil-ability-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-realty-real-estate-nyse-us-68b1
domain.org/url[0]/url[1]/abr-a-arbor-realty-real-estate-nyse-us-8c1d
domain.org/url[0]/url[1]/abr-b-arbor-realty-real-estate-nyse-us-97f2
domain.org/url[0]/url[1]/abr-c-arbor-realty-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
beginner php algorithm strings url
beginner php algorithm strings url
asked 51 mins ago
EmmaEmma
164112
164112
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f215553%2fgenerate-a-daily-sitemap-and-update-using-a-url-string-input%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f215553%2fgenerate-a-daily-sitemap-and-update-using-a-url-string-input%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown