Jump to content

phpnew

Members
  • Posts

    33
  • Joined

  • Last visited

  • Days Won

    1

phpnew last won the day on August 12 2020

phpnew had the most liked content!

Profile Information

  • Gender
    Not Telling

phpnew's Achievements

Member

Member (2/5)

2

Reputation

  1. Thanks very much. No wonder I was not able to find a solution. Until now, I was able to get the values out in the money formatted form as there was no need for further use of those variables. I can rework it so it's all numerical until the very end. Thanks again
  2. Hi, I have PHP code that takes care of currency values that I show on a website. The purpose is simple, maintain service/product prices in one script and print PHP variables wherever I need them on the site. here is the code: function getMoneyUS( $pricesUS ) { $formatter = new NumberFormatter('en_US', NumberFormatter::CURRENCY); return $formatter->formatCurrency($pricesUS, 'USD'); } function getMoneyUSd( $pricesUS ) { $formatter = new NumberFormatter('en_US', NumberFormatter::CURRENCY); $formatter->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, 0); return $formatter->formatCurrency($pricesUS, 'USD'); } The two functions are for prices with and without decimals (cents in this case). Then, for each service, I enter the price manually, like in these examples: $price1 = getMoneyUSd(30); $price2 = getMoneyUS(74.99); Now, in some cases, I need to combine prices (bundles), and whatever I tried to add those values produced either an error breaking the page, or $0.00 the best. And even when I get the zero, there would be a "PHP Warning: A non-numeric value encountered" I tried using some PHP functions to convert string to an integer, and to use number format, but could not make it work. For the $0 result, I would do this: $bundle = getMoneyUS($price1 + $price2) Since the numbers are already formatted as currencies, is there a way to add them up (to sum), or I have to do some multiple conversions before getting them out as currencies? Thank you
  3. Got it! $item = array('L','N'); foreach ($item as $x) { $link["{$x}1c2"]=$link["{$x}1c2CP"]=site1.com; $link["{$x}1c3"]=$link["{$x}1c3CP"]=site2.com;} Thanks!
  4. One more question on this. If I have multiple lines of $link variable, can I use "for each" statement only once, and then list my $link variables under, in some sort of brackets? This is what I would have now: foreach(['F','N'] as $x) $link["be{$x}1LP"]="https://www.site1.com"; foreach(['F','N'] as $x) $link["be{$x}2LP"]="https://www.site2.com"; foreach(['F','N'] as $x) $link["be{$x}3LP"]="https://www.site3.com"; Thank you
  5. I have such lines of code: $link["beF1LP"]="https://www.site.com"; $link["beN1LP"]="https://www.site.com"; I know I can simplify it like this: $link["beF1LP"]=$link["beN1LP"]="https://www.site.com"; But I wanted something like this: $link["be(F|N)1LP"]="https://www.site.com"; Which did not work. How do I get it working for the string inside the brackets and under the quotes while using OR and/or other operators? Thank you
  6. Initially, I tried using it without "$formatter" variable. I thought that in functions I would use it as in the one with money_format, no $ sign except for the variable that is there for the price. That is why it did not work. I searched around, tried various things. Now as I'm typing this, i figure I obviously do not need that EOL which I guess stands for "End of line" so I'll take it out.
  7. Eh! If I knew how to do that, I would not come here to ask for help. I change this now, and I'm good for another 3 years, lol. I don't do programming.
  8. Official PHP website in most cases is not of much use for people that ask for help in places like here, on the forum. I was certainly first there, looking into four or five examples from 5 to 9 years ago that were just repeating the official ones. I could not use it for what I came up with at the end. Anyhow, I was able to figure it out, test and get no errors reported while getting the desired result. And here is the full code, for whoever needs it in the future: function getMoneyUS( $pricesUS ) { $formatter = new NumberFormatter('en_US', NumberFormatter::CURRENCY); return $formatter->formatCurrency($pricesUS, 'USD') . PHP_EOL; } function getMoneyUSd( $pricesUS ) { $formatter = new NumberFormatter('en_US', NumberFormatter::CURRENCY); $formatter->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, 0); return $formatter->formatCurrency($pricesUS, 'USD') . PHP_EOL; } It's for USD in this example. To change the currency you change the locale in the second line, then the currency code in the following one. The first function is for regular prices with decimals, and the second one is for amounts with no decimals. I need this to show the discount amounts that are always shown as rounded numbers, like Save $20 and so on. MAX_FRACTION_DIGITS sets the number of decimals. Thanks
  9. Hi, I have this money related function: function getMoneyUS( $pricesUS ) { setlocale( LC_MONETARY, 'en_US.UTF-8' ); return money_format( '%n', $pricesUS ); } Now, after the update to 7.4, it is showing in the logs as deprecated. The issue is money_format. I tried with NumberFormatter::formatCurrency but I either get an error or empty results. Examples I'm finding are not functions that can be applied multiple times, but for fixed values only. Examples like this: $fmt = numfmt_create( 'de_DE', NumberFormatter::CURRENCY ); echo numfmt_format_currency($fmt, 1234567.891234567890000, "EUR")."\n"; Or this: $fmt = new NumberFormatter( 'de_DE', NumberFormatter::CURRENCY ); echo $fmt->formatCurrency(1234567.891234567890000, "EUR")."\n"; I could not adapt them to my function. I understand that I do not need setlocale anymore, but this NumberFormatter only. But the exact working replacement is a challenge for me. I tried removing variable $fmt and replacing the fixed amount with my $priceUS, always some error or no result.
  10. So far I found that if the server is configured to have PHP run in Apache module, I can use AcceptPathInfo Off in .htaccess to turn PATH_INFO off so URLs like page.php/something return 404 (even in shared hosting). Otherwise page.php/something would return the content of page.php which is what I don't want. The trouble I have is with servers that have PHP configured in CGI module. Here AcceptPathInfo Off in .htaccess has no effect. Is there any way to turn this OFF in PHP as CGI environment (shared hosting)? Thanks
  11. Hi there, I have a website on shared hosting where PHP is configured to run in CGI module. In order to have my PHP code working, I use this in .htaccess: AddHandler application/x-httpd-php5 .html .htm AddType x-mapp-php5 .html .htm But that creates an environment that returns 200 OK on URLs with trailing slash and any string after that: Example: Regular URL: example.com/page.html URL with trailing slash: example.com/page.html/whatever For the second one, it should return 404, but with PHP handler being used, it actually returns page.html with broken links which causes further creation of infinite number of pages with duplicate content. Now about AcceptPathInfo. If the server is configured as Apache module, the command AcceptPathInfo Off in .htaccess resolves this issue. But with the configuration as CGI module, it does not matter. Why is this and is there a workaround? Thanks
  12. ... end everything works like a charm. Thank you so much to all that took time to read through this. We did not just solve our problem, but learned a lesson in regards of "how to post a question" Thanks again.
  13. Things are changing quickly here... </head> <?php $q = $_SERVER["QUERY_STRING"]; $code = '<body> <p><a href="links/links.php?m=link23999">Outgoing Link 1</a></p> <p><a href="links/links.php?m=link24999">Outgoing Link 2</a></p> <p><a href="page1.html">Page 1</a></p> <p><a href="page2.html">Page 2</a></p> </body>'; echo str_replace('html">','html?' . $q . '">',$code); echo str_replace('999">','&myVariable=' . $q . '">',$code); ?> </html> All works... except that page gets echoed twice. How do I do echo for both str_replace in one time? Thanks.
  14. <body> <?php $q = $_SERVER["QUERY_STRING"]; ?> <p> </p> <p><a href="links/links.php?m=link23">Outgoing Link 1</a></p> <p> </p> <p><a href="page1.html">Page 1</a></p> </body> Assuming that for a given session the variable $q=somekeyword, the result should be: <body> <p> </p> <p><a href="links/links.php?m=link23&myVariable=somekeyword">Outgoing Link 1</a></p> <p> </p> <p><a href="page1.html?somekeyword">Page 1</a></p> </body> Please note that the number of outgoing and internal links can be different for each page. For links of PHP type, the appended string should be "&myVariable=somekeyword" For links of HTML type, the appended string should be "?somekeyword" I hope this sheds some light to my initial non-understandable call for help. Thank you.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.