Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #19357 > unrolled thread
| Started by | The Doctor <doctor@doctor.nl2k.ab.ca> |
|---|---|
| First post | 2023-03-02 12:44 +0000 |
| Last post | 2023-04-15 13:52 +0000 |
| Articles | 20 on this page of 44 — 8 participants |
Back to article view | Back to comp.lang.php
Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-02 12:44 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-02 14:23 +0100
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-03 01:03 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-03 10:36 +0100
Re: Replace punctuation in an associative array Ezimene nimi Teine nimi <techfan55555@hotmail.com> - 2023-03-08 09:22 -0800
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-09 01:24 +0000
Re: Replace punctuation in an associative array Arno Welzel <usenet@arnowelzel.de> - 2023-03-03 08:14 +0100
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-04 05:19 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-04 11:07 +0100
Re: Replace punctuation in an associative array Arno Welzel <usenet@arnowelzel.de> - 2023-03-04 14:42 +0100
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-04 14:57 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-04 16:38 +0100
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-05 00:41 +0100
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-04 23:58 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-05 01:39 +0100
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-03-05 00:52 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-05 12:16 +0100
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-05 14:08 +0000
Re: Bureaucracy (Was: Replace punctuation in an associative array) "J.O. Aho" <user@example.net> - 2023-03-06 09:30 +0100
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-07 16:43 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-07 18:56 +0100
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-07 22:53 +0000
Re: Replace punctuation in an associative array Arno Welzel <usenet@arnowelzel.de> - 2023-03-08 23:44 +0100
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-09 01:25 +0000
Re: Replace punctuation in an associative array Arno Welzel <usenet@arnowelzel.de> - 2023-03-10 09:08 +0100
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-10 15:20 +0000
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-01 14:08 +0000
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-06 00:26 +0000
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-12 22:45 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-04-13 07:41 +0200
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-13 11:50 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-04-13 14:26 +0200
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-13 22:37 +0000
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-14 01:12 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-04-14 19:34 +0200
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-14 22:21 +0000
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-16 12:40 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-04-16 22:03 +0200
Re: Replace punctuation in an associative array Ezimene nimi Teine nimi <yyyyyeeeee00000@writeme.com> - 2023-03-06 03:23 -0800
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-06 16:21 +0000
Re: Replace punctuation in an associative array V <vvvvvvvvvvvvvvvvvvvv11111@mail.ee> - 2023-04-03 06:55 -0700
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-03 14:18 +0000
Re: Replace punctuation in an associative array Angel <heyeeeeeeeeeeeeeeeeeee@gmail.com> - 2023-04-15 05:33 -0700
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-15 13:52 +0000
Page 1 of 3 [1] 2 3 Next page →
| From | The Doctor <doctor@doctor.nl2k.ab.ca> |
|---|---|
| Date | 2023-03-02 12:44 +0000 |
| Subject | Replace punctuation in an associative array |
| Message-ID | <ttq5np$i9r$50@gallifrey.nk.ca> |
I wish to replace [[ with [ AND ]] with ] in an associative array . How can I do this? -- Member - Liberal International This is doctor@nk.ca Ici doctor@nk.ca Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising! Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b Only an evil person could punish someone for doing good, and only an evil ideology could allow it. -unknown Beware https://mindspring.com
[toc] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2023-03-02 14:23 +0100 |
| Message-ID | <k6bmapFcv37U1@mid.individual.net> |
| In reply to | #19357 |
On 3/2/23 13:44, The Doctor wrote:
A wild guess, this still to do with your json, which you have asked help
with quite often.
> I wish to replace [[ with [
>
> AND
>
> ]] with ] in an associative array .
Don't store objects as an array and place those arrays in an array.
Create an object and place the object into the array which is part of
your main-object.
> How can I do this?
If you just look at a string, string replace could work quite well to do
this
str_replace('[[','[',$str);
[toc] | [prev] | [next] | [standalone]
| From | The Doctor <doctor@doctor.nl2k.ab.ca> |
|---|---|
| Date | 2023-03-03 01:03 +0000 |
| Message-ID | <ttrh05$fo7$68@gallifrey.nk.ca> |
| In reply to | #19358 |
J.O. Aho <user@example.net> wrote:
: On 3/2/23 13:44, The Doctor wrote:
: A wild guess, this still to do with your json, which you have asked help
: with quite often.
: > I wish to replace [[ with [
: >
: > AND
: >
: > ]] with ] in an associative array .
: Don't store objects as an array and place those arrays in an array.
: Create an object and place the object into the array which is part of
: your main-object.
All right. Even in a recursive loop?
: > How can I do this?
: If you just look at a string, string replace could work quite well to do
: this
: str_replace('[[','[',$str);
Woth a try.
--
Member - Liberal International This is doctor@nk.ca Ici doctor@nk.ca
Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising!
Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b
The kingdom is inside out. -unknown Beware https://mindspring.com
[toc] | [prev] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2023-03-03 10:36 +0100 |
| Message-ID | <k6dtc6FufhjU1@mid.individual.net> |
| In reply to | #19359 |
On 3/3/23 02:03, The Doctor wrote:
> J.O. Aho <user@example.net> wrote:
> : On 3/2/23 13:44, The Doctor wrote:
>
> : A wild guess, this still to do with your json, which you have asked help
> : with quite often.
>
> : > I wish to replace [[ with [
> : >
> : > AND
> : >
> : > ]] with ] in an associative array .
>
> : Don't store objects as an array and place those arrays in an array.
>
> : Create an object and place the object into the array which is part of
> : your main-object.
>
> All right. Even in a recursive loop?
A recursive function should just return an array, but this array needs
to be assigned to the objects array variable, not as a cell in that array.
_not_ like:
$object->array[] = recursiveLoopFunction($inputdate);
but like:
$object->array = recursiveLoopFunction($inputdate);
> : > How can I do this?
>
> : If you just look at a string, string replace could work quite well to do
> : this
> : str_replace('[[','[',$str);
>
> Woth a try.
I wouldn't say it's worth trying, it's tends to be better to do things
the right way from the beginning. I do recommend you make classes that
represents how your json should look like for example if you have:
{
"order_id" : 12334,
"total_tax": 1.10,
"total_value": 100,
"cart": [
{
"name": "item1",
"quantity": 1,
"price": 10
},
{
"name": "item2",
"quantity": 2,
"price": 45
},
]
}
This would be two classes, the item class and the order class
class item {
public string $name;
public int $quantity;
public float $price;
}
class order {
public int $order_id;
public float $total_tax;
public float $total_value;
public $cart = array();
}
here is an example code
<?php
// this is the input data we assume this is your POST data
$inputData = array("order_id" => 1234, "cart" => array( array("name" =>
"item1", "quantity" => 1, "price" => 10), array("name" => "item2",
"quantity" => 2, "price" => 45) ) );
// this is the classes we have that describes the json
// we do init some values, just in case.
class item {
public string $name;
public int $quantity = 0;
public float $price = 0.0;
}
class order {
public int $order_id;
public float $total_tax = 0.0;
public float $total_value = 0.0;
public $cart = array();
}
// here we assign the values from the post data
// without really verifying the data is okay
$order = new order();
$order->order_id = $inputData["order_id"];
$tax = 0.011; // an assumed tax % for this simplified example
// now we process the cart items
// we should take the price from a database
// instead of trusting a user
foreach($inputData["cart"] as $itemData) {
$item = new item();
$item->name = $itemData["name"];
$item->quantity = $itemData["quantity"];
$item->price = $itemData["price"];
// we add the item to the cart array in the order object
$order->cart[] = $item;
// we store the totla_value in a local variable as we need it for the tax
$total_value = $item->quantity * $item->price;
// update the order total value/tax
$order->total_value += $total_value;
$order->total_tax += $tax * $total_value;
}
// the json should be the same as the one above the code, a zero missing,
// but should cause any issues as the value is equal.
echo json_encode($order, JSON_PRETTY_PRINT);
echo "\n"; // just a new line so that the prompt will come back below
the json
?>
Don't forget that you can make functions that do parts of the moving
data from the post data to the different objects, this way you make it
easier to see what the code does and should make it easier to locate
where a fault is without being distracted by code not related.
--
//Aho
[toc] | [prev] | [next] | [standalone]
| From | Ezimene nimi Teine nimi <techfan55555@hotmail.com> |
|---|---|
| Date | 2023-03-08 09:22 -0800 |
| Message-ID | <b0085144-a1fa-4a4d-9f5c-538892d94c39n@googlegroups.com> |
| In reply to | #19358 |
⠀⠀⠀⠀⠀Good ⠀⠀⠀evening⠀⠀⠀⠀,⠀⠀⠀J. O. Aho⠀⠀⠀.
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀Are ⠀⠀⠀You ⠀⠀⠀rich⠀⠀ ? ⠀⠀If ⠀⠀⠀yes⠀⠀⠀,⠀⠀⠀would ⠀⠀You ⠀⠀help ⠀⠀⠀me ⠀⠀financially⠀? ⠀⠀⠀I'm ⠀⠀⠀having ⠀⠀⠀no ⠀⠀⠀job ⠀⠀momentarily⠀⠀.
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀I'd ⠀⠀⠀like ⠀⠀⠀to ⠀⠀buy ⠀⠀⠀newer ⠀⠀mobile ⠀⠀⠀phone⠀(⠀IPhone 14⠀)⠀⠀. ⠀⠀I'm ⠀⠀having ⠀⠀⠀momentarily ⠀⠀⠀old⠀⠀ IPhone 5s⠀⠀.
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀1100 ⠀⠀dollars ⠀⠀would ⠀⠀be ⠀⠀big ⠀help⠀.
⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀Stay⠀⠀ continueingly ⠀⠀⠀shining⠀⠀⠀,⠀⠀⠀J.O. Aho⠀⠀⠀!
⠀
⠀
⠀⠀⠀⠀⠀Guy⠀ from ⠀Viljandi⠀⠀(⠀⠀K⠀⠀⠀⠀⠀r⠀⠀⠀⠀⠀⠀i⠀⠀⠀⠀⠀⠀s⠀⠀⠀⠀⠀⠀t⠀⠀⠀⠀⠀j⠀⠀⠀⠀a⠀⠀⠀n ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀R⠀⠀⠀⠀⠀o⠀⠀⠀⠀b⠀⠀⠀a⠀⠀⠀⠀m⠀⠀⠀⠀)
⠀
⠀
⠀
⠀
⠀
⠀
⠀⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀
⠀⠀
On Thursday, March 2, 2023 at 3:23:46 PM UTC+2, J.O. Aho wrote:
> On 3/2/23 13:44, The Doctor wrote:
>
> A wild guess, this still to do with your json, which you have asked help
> with quite often.
> > I wish to replace [[ with [
> >
> > AND
> >
> > ]] with ] in an associative array .
> Don't store objects as an array and place those arrays in an array.
>
> Create an object and place the object into the array which is part of
> your main-object.
> > How can I do this?
> If you just look at a string, string replace could work quite well to do
> this
> str_replace('[[','[',$str);
[toc] | [prev] | [next] | [standalone]
| From | The Doctor <doctor@doctor.nl2k.ab.ca> |
|---|---|
| Date | 2023-03-09 01:24 +0000 |
| Message-ID | <tubcgn$28r3$26@gallifrey.nk.ca> |
| In reply to | #19391 |
Ezimene nimi Teine nimi <techfan55555@hotmail.com> wrote:
: 4qCA4qCA4qCA4qCA4qCAR29vZCDioIDioIDioIBldmVuaW5n4qCA4qCA4qCA4qCALOKggOKggOKg
: gEouIE8uIEFob+KggOKggOKggC4K4qCA4qCA4qCA4qCA4qCA4qCA4qCA4qCA4qCA4qCA4qCA4qCA
: 4qCA4qCA4qCA4qCA4qCA4qCA4qCA4qCA4qCA4qCA4qCA4qCA4qCA4qCA4qCA4qCACuKggOKggOKg
: gOKggOKggEFyZSDioIDioIDioIBZb3Ug4qCA4qCA4qCAcmljaOKggOKggCA/IOKggOKggElmIOKg
: gOKggOKggHllc+KggOKggOKggCzioIDioIDioIB3b3VsZCDioIDioIBZb3Ug4qCA4qCAaGVscCDi
: oIDioIDioIBtZSDioIDioIBmaW5hbmNpYWxseeKggD8g4qCA4qCA4qCASSdtIOKggOKggOKggGhh
: dmluZyDioIDioIDioIBubyDioIDioIDioIBqb2Ig4qCA4qCAbW9tZW50YXJpbHnioIDioIAuCuKg
: gOKggOKggOKggOKggOKggOKggOKggOKggOKggOKggOKggOKggOKggOKggOKggOKggArioIDioIDi
: oIDioIDioIBJJ2Qg4qCA4qCA4qCAbGlrZSDioIDioIDioIB0byDioIDioIBidXkg4qCA4qCA4qCA
: bmV3ZXIg4qCA4qCAbW9iaWxlIOKggOKggOKggHBob25l4qCAKOKggElQaG9uZSAxNOKggCnioIDi
: oIAuIOKggOKggEknbSDioIDioIBoYXZpbmcg4qCA4qCA4qCAbW9tZW50YXJpbHkg4qCA4qCA4qCA
: b2xk4qCA4qCAIElQaG9uZSA1c+KggOKggC4K4qCA4qCA4qCA4qCA4qCA4qCA4qCA4qCA4qCA4qCA
: CuKggOKggOKggOKggOKggDExMDAg4qCA4qCAZG9sbGFycyDioIDioIB3b3VsZCDioIDioIBiZSDi
: oIDioIBiaWcg4qCAaGVscOKggC4K4qCA4qCA4qCA4qCA4qCACuKggOKggOKggOKggOKggFN0YXni
: oIDioIAgY29udGludWVpbmdseSDioIDioIDioIBzaGluaW5n4qCA4qCA4qCALOKggOKggOKggEou
: Ty4gQWhv4qCA4qCA4qCAIQrioIAK4qCACuKggOKggOKggOKggOKggEd1eeKggCBmcm9tIOKggFZp
: bGphbmRp4qCA4qCAKOKggOKggEvioIDioIDioIDioIDioIBy4qCA4qCA4qCA4qCA4qCA4qCAaeKg
: gOKggOKggOKggOKggOKggHPioIDioIDioIDioIDioIDioIB04qCA4qCA4qCA4qCA4qCAauKggOKg
: gOKggOKggGHioIDioIDioIBuIOKggOKggOKggOKggOKggOKggOKggOKggOKggOKggOKggOKggOKg
: gOKggFLioIDioIDioIDioIDioIBv4qCA4qCA4qCA4qCAYuKggOKggOKggGHioIDioIDioIDioIBt
: 4qCA4qCA4qCA4qCAKQrioIAK4qCACuKggArioIAK4qCACuKggArioIDioIAK4qCACuKggArioIAK
: 4qCACuKggArioIAK4qCACuKggArioIAK4qCACuKggArioIAK4qCACuKggArioIAK4qCACuKggAri
: oIAK4qCACuKggArioIAK4qCACuKggArioIAK4qCACuKggArioIAK4qCACuKggArioIAK4qCACuKg
: gArioIAK4qCACuKggArioIAK4qCACuKggOKggAoKCk9uIFRodXJzZGF5LCBNYXJjaCAyLCAyMDIz
: IGF0IDM6MjM6NDbigK9QTSBVVEMrMiwgSi5PLiBBaG8gd3JvdGU6Cj4gT24gMy8yLzIzIDEzOjQ0
: LCBUaGUgRG9jdG9yIHdyb3RlOiAKPiAKPiBBIHdpbGQgZ3Vlc3MsIHRoaXMgc3RpbGwgdG8gZG8g
: d2l0aCB5b3VyIGpzb24sIHdoaWNoIHlvdSBoYXZlIGFza2VkIGhlbHAgCj4gd2l0aCBxdWl0ZSBv
: ZnRlbi4KPiA+IEkgd2lzaCB0byByZXBsYWNlIFtbIHdpdGggWyAKPiA+IAo+ID4gQU5EIAo+ID4g
: Cj4gPiBdXSB3aXRoIF0gaW4gYW4gYXNzb2NpYXRpdmUgYXJyYXkgLgo+IERvbid0IHN0b3JlIG9i
: amVjdHMgYXMgYW4gYXJyYXkgYW5kIHBsYWNlIHRob3NlIGFycmF5cyBpbiBhbiBhcnJheS4gCj4g
: Cj4gQ3JlYXRlIGFuIG9iamVjdCBhbmQgcGxhY2UgdGhlIG9iamVjdCBpbnRvIHRoZSBhcnJheSB3
: aGljaCBpcyBwYXJ0IG9mIAo+IHlvdXIgbWFpbi1vYmplY3QuCj4gPiBIb3cgY2FuIEkgZG8gdGhp
: cz8KPiBJZiB5b3UganVzdCBsb29rIGF0IGEgc3RyaW5nLCBzdHJpbmcgcmVwbGFjZSBjb3VsZCB3
: b3JrIHF1aXRlIHdlbGwgdG8gZG8gCj4gdGhpcyAKPiBzdHJfcmVwbGFjZSgnW1snLCdbJywkc3Ry
: KTsK
This abusive spamtroll came from
X-Received: by 2002:a05:620a:d4d:b0:742:83ee:f569 with SMTP id o13-20020a05620a
0d4d00b0074283eef569mr4089391qkl.13.1678296151146;
Wed, 08 Mar 2023 09:22:31 -0800 (PST)
X-Received: by 2002:a81:ac1a:0:b0:533:cf4e:9a80 with SMTP id
k26-20020a81ac1a000000b00533cf4e9a80mr11627665ywh.6.1678296150894; Wed, 08
Mar 2023 09:22:30 -0800 (PST)
Path: news.nk.ca!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.c
om!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!new
s.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!g
oogle-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.php
Date: Wed, 8 Mar 2023 09:22:30 -0800 (PST)
In-Reply-To: <k6bmapFcv37U1@mid.individual.net>
Injection-Info: google-groups.googlegroups.com; posting-host=85.253.192.155; po
sting-account=ogslnwoAAACd9vU9PADzlWBA81fSuNpL
NNTP-Posting-Host: 85.253.192.155
References: <ttq5np$i9r$50@gallifrey.nk.ca> <k6bmapFcv37U1@mid.individual.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b0085144-a1fa-4a4d-9f5c-538892d94c39n@googlegroups.com>
Subject: Re: Replace punctuation in an associative array
From: Ezimene nimi Teine nimi <techfan55555@hotmail.com>
Injection-Date: Wed, 08 Mar 2023 17:22:31 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: base64
X-Received-Bytes: 3833
Xref: news.nk.ca comp.lang.php:167980
Spamtrollers are trolls posting useless spam thinking it is content
but are posting useless noise. Spamtrolls are newsgroup vandals!
Thoses trolls are as bad as Donald
Trump on Twitter.
This makes
https://groups.google.com/search/conversations?q=Depeer%20Google%20Groups
Depeer Google groups Now!!
--
Member - Liberal International This is doctor@nk.ca Ici doctor@nk.ca
Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising!
Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b
Hiding reality from people is no way to deal with reality. -unknown Beware https://mindspring.com
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2023-03-03 08:14 +0100 |
| Message-ID | <k6dl2dFtv97U1@mid.individual.net> |
| In reply to | #19357 |
The Doctor, 2023-03-02 13:44:
> I wish to replace [[ with [
>
> AND
>
> ]] with ] in an associative array .
>
> How can I do this?
What do you mean with "in an associative array"? The values? The keys?
If you want to replace the characters in values:
<?php
$array = [
'value 1' => '[[something 1',
'value 2' => 'something 2]]',
];
// Output array as it was before
print_r($array);
foreach($array as $key => $value)
{
$array[$key] = str_replace(
[ '[[', ']]' ],
[ '[', ']' ],
$value
);
}
// Output as it was afterwards
print_r($array);
--
Arno Welzel
https://arnowelzel.de
[toc] | [prev] | [next] | [standalone]
| From | The Doctor <doctor@doctor.nl2k.ab.ca> |
|---|---|
| Date | 2023-03-04 05:19 +0000 |
| Message-ID | <ttukdq$1t41$1@gallifrey.nk.ca> |
| In reply to | #19360 |
Arno Welzel <usenet@arnowelzel.de> wrote:
: The Doctor, 2023-03-02 13:44:
: > I wish to replace [[ with [
: >
: > AND
: >
: > ]] with ] in an associative array .
: >
: > How can I do this?
: What do you mean with "in an associative array"? The values? The keys?
: If you want to replace the characters in values:
: <?php
: $array = [
: 'value 1' => '[[something 1',
: 'value 2' => 'something 2]]',
: ];
: // Output array as it was before
: print_r($array);
: foreach($array as $key => $value)
: {
: $array[$key] = str_replace(
: [ '[[', ']]' ],
: [ '[', ']' ],
: $value
: );
: }
: // Output as it was afterwards
: print_r($array);
What is happening is that the arrauy is being formed by a subarray
and the end product is seeing a [[ at the start and a ]]
at the end when it should be seeing a [ at the start and a ] at the end.
--
Member - Liberal International This is doctor@nk.ca Ici doctor@nk.ca
Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising!
Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b
We cannot defy gravity without paying a price. -unknown Beware https://mindspring.com
[toc] | [prev] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2023-03-04 11:07 +0100 |
| Message-ID | <k6gjj7FdcegU1@mid.individual.net> |
| In reply to | #19362 |
On 3/4/23 06:19, The Doctor wrote:
> Arno Welzel <usenet@arnowelzel.de> wrote:
> : The Doctor, 2023-03-02 13:44:
>
> : > I wish to replace [[ with [
> : >
> : > AND
> : >
> : > ]] with ] in an associative array .
> : >
> : > How can I do this?
>
> : What do you mean with "in an associative array"? The values? The keys?
>
> : If you want to replace the characters in values:
>
> : <?php
> : $array = [
> : 'value 1' => '[[something 1',
> : 'value 2' => 'something 2]]',
> : ];
>
> : // Output array as it was before
> : print_r($array);
>
> : foreach($array as $key => $value)
> : {
> : $array[$key] = str_replace(
> : [ '[[', ']]' ],
> : [ '[', ']' ],
> : $value
> : );
> : }
>
> : // Output as it was afterwards
> : print_r($array);
>
> What is happening is that the arrauy is being formed by a subarray
> and the end product is seeing a [[ at the start and a ]]
> at the end when it should be seeing a [ at the start and a ] at the end.
>
>
>
You place your object in too many arrays, it had been better doing it
the "right way" from the beginning,
It's not that hard to create the json you want when using classes, in
like 20mins I managed to generate this json from my objects:
{
"store_id": null,
"api_token": null,
"checkout_id": null,
"txn_total": null,
"environment": null,
"action": null,
"token": [
{
"data_key": "1234",
"issuer_id": "645sddfvdrt4tefd"
},
{
"data_key": "5678",
"issuer_id": "645sddfvdrt4tefd"
}
],
"ask_cvv": null,
"order_no": null,
"cust_id": null,
"dynamic_descriptor": null,
"language": null,
"recur": {
"bill_now": null,
"recur_amount": null,
"start_date": null,
"recur_unit": null,
"recur_period": null,
"number_of_recurs": null
},
"cart": {
"items": [
{
"url": "https:\/\/example.net\/item?id=1",
"description": "item 1",
"product_code": "1",
"unit_cost": "100",
"quantity": "1"
},
{
"url": "https:\/\/example.net\/item?id=2",
"description": "item 2",
"product_code": "2",
"unit_cost": "200",
"quantity": "1"
}
],
"subtotal": null,
"tax": {
"amount": null,
"description": null,
"rate": null
}
},
"contact_details": {
"first_name": null,
"last_name": null,
"email": null,
"phone": null
},
"shipping_details": {
"address_1": null,
"address_2": null,
"city": null,
"province": null,
"country": null,
"postal_code": null
},
"billing_details": {
"address_1": null,
"address_2": null,
"city": null,
"province": null,
"country": null,
"postal_code": null
}
}
I assumed that all values has to always be there, like an empty token
list would be [] instead of null and so on, add two tokens and two items.
using __construct(...) you could make it possible to input the values at
once instead of how I done creating the object and then assign each
variable one by one. You have the opportunity to improve things.
https://pastebin.com/jnz1RYWj
sadly Moneris seems to want everything to be as strings, if you could
have used float/decimal/duble/int then you didn't have to convert
between string and a numeric value back and forth.
--
//Aho
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2023-03-04 14:42 +0100 |
| Message-ID | <k6h06kFfavmU1@mid.individual.net> |
| In reply to | #19362 |
The Doctor, 2023-03-04 06:19: [...] > What is happening is that the arrauy is being formed by a subarray > and the end product is seeing a [[ at the start and a ]] > at the end when it should be seeing a [ at the start and a ] at the end. Then don't create a subarray! Again: if you need objects, then create objects and not arrays! -- Arno Welzel https://arnowelzel.de
[toc] | [prev] | [next] | [standalone]
| From | The Doctor <doctor@doctor.nl2k.ab.ca> |
|---|---|
| Date | 2023-03-04 14:57 +0000 |
| Message-ID | <ttvm80$1hgn$1@gallifrey.nk.ca> |
| In reply to | #19364 |
Arno Welzel <usenet@arnowelzel.de> wrote: : The Doctor, 2023-03-04 06:19: : [...] : > What is happening is that the arrauy is being formed by a subarray : > and the end product is seeing a [[ at the start and a ]] : > at the end when it should be seeing a [ at the start and a ] at the end. : Then don't create a subarray! : Again: if you need objects, then create objects and not arrays! J.A AHo and Arno , 2 Problems here a) Converting a page from a programmer that did not use classes b) Web pages that actually you can search adn the results give you not what you want. If you 2 had quality web pages on PHP programming , you should be up there and not the pages Google, yahoo et al as showing. -- Member - Liberal International This is doctor@nk.ca Ici doctor@nk.ca Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising! Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b We cannot defy gravity without paying a price. -unknown Beware https://mindspring.com
[toc] | [prev] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2023-03-04 16:38 +0100 |
| Message-ID | <k6h6vcFdcehU1@mid.individual.net> |
| In reply to | #19365 |
On 3/4/23 15:57, The Doctor wrote: > Arno Welzel <usenet@arnowelzel.de> wrote: > : The Doctor, 2023-03-04 06:19: > > : [...] > : > What is happening is that the arrauy is being formed by a subarray > : > and the end product is seeing a [[ at the start and a ]] > : > at the end when it should be seeing a [ at the start and a ] at the end. > > : Then don't create a subarray! > > : Again: if you need objects, then create objects and not arrays! > > > J.A AHo and Arno , > > 2 Problems here > > a) Converting a page from a programmer that did not use classes Then you need to rewrite things, how many weeks hasn't you spent on trying to get a proper json of the mess of arrays. Doing it right and rewrite, I think you would have finished a month ago already. Take a look at the following code, test it too and you see the benefit https://pastebin.com/yJC9DJWs If you rewrite things now, you will save time and efforts in the future, specially if there comes changes to the API. > b) Web pages that actually you can search adn > the results give you not what you want. > > If you 2 had quality web pages on PHP > programming , you should be up there and not the pages > Google, yahoo et al as showing. php.net is IMHO a really good source for information. Sometimes Packt hands out free PHP books, just keep on looking at https://www.packtpub.com/free-learning one book a day and after a while you will see the same book again... -- //Aho
[toc] | [prev] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2023-03-05 00:41 +0100 |
| Message-ID | <k6i39aFkhvjU1@mid.individual.net> |
| In reply to | #19366 |
On 3/4/23 16:38, J.O. Aho wrote: > On 3/4/23 15:57, The Doctor wrote: >> a) Converting a page from a programmer that did not use classes > > Then you need to rewrite things, how many weeks hasn't you spent on > trying to get a proper json of the mess of arrays. Doing it right and > rewrite, I think you would have finished a month ago already. > > Take a look at the following code, test it too and you see the benefit > https://pastebin.com/yJC9DJWs > > If you rewrite things now, you will save time and efforts in the future, > specially if there comes changes to the API. Looking at your old posts, using the above code you would endup with something like this (not tested): https://pastebin.com/bF6bZseu this has same issues with unvalidated data, but at least now no one will get the items for free as the transaction value is calculated while adding items to the carts items array. if it's mainly changing how to load values from post, it's a short times convertion, if you store vallues in the session, then you need slightly more changes, specially if you need to access values, but should be quit simple to find out where with help of php lint function (php -l sourcodefile.php). Keep in mind nothin is a 100% solution for your issue as I haven't bothered really go into the API that is used but just a bit based on your posts in this group. And please, what ever you do, don't go with the str_replace, it's not the solution to your issue, it will just make things a lot harder to maintain. -- //Aho
[toc] | [prev] | [next] | [standalone]
| From | The Doctor <doctor@doctor.nl2k.ab.ca> |
|---|---|
| Date | 2023-03-04 23:58 +0000 |
| Message-ID | <tu0lvb$1ph9$52@gallifrey.nk.ca> |
| In reply to | #19367 |
J.O. Aho <user@example.net> wrote: : On 3/4/23 16:38, J.O. Aho wrote: : > On 3/4/23 15:57, The Doctor wrote: : >> a) Converting a page from a programmer that did not use classes : > : > Then you need to rewrite things, how many weeks hasn't you spent on : > trying to get a proper json of the mess of arrays. Doing it right and : > rewrite, I think you would have finished a month ago already. : > : > Take a look at the following code, test it too and you see the benefit : > https://pastebin.com/yJC9DJWs : > : > If you rewrite things now, you will save time and efforts in the future, : > specially if there comes changes to the API. : Looking at your old posts, using the above code you would endup with : something like this (not tested): : https://pastebin.com/bF6bZseu : this has same issues with unvalidated data, but at least now no one will : get the items for free as the transaction value is calculated while : adding items to the carts items array. : if it's mainly changing how to load values from post, it's a short times : convertion, if you store vallues in the session, then you need slightly : more changes, specially if you need to access values, but should be quit : simple to find out where with help of php lint function (php -l : sourcodefile.php). : Keep in mind nothin is a 100% solution for your issue as I haven't : bothered really go into the API that is used but just a bit based on : your posts in this group. : And please, what ever you do, don't go with the str_replace, it's not : the solution to your issue, it will just make things a lot harder to : maintain. Actually the class approach works better. Too bad Google does not pick that up in their searches for JSON> -- Member - Liberal International This is doctor@nk.ca Ici doctor@nk.ca Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising! Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b We cannot defy gravity without paying a price. -unknown Beware https://mindspring.com
[toc] | [prev] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2023-03-05 01:39 +0100 |
| Message-ID | <k6i6l8FksscU2@mid.individual.net> |
| In reply to | #19368 |
On 3/5/23 00:58, The Doctor wrote: > J.O. Aho <user@example.net> wrote: > : https://pastebin.com/bF6bZseu > : Keep in mind nothin is a 100% solution for your issue as I haven't > : bothered really go into the API that is used but just a bit based on > : your posts in this group. > > : And please, what ever you do, don't go with the str_replace, it's not > : the solution to your issue, it will just make things a lot harder to > : maintain. > > > Actually the class approach works better. That's good, just tweak it to fit your user case, just don't forget validate the input data. > Too bad Google does not pick that up > in their searches for JSON> Much depends on the requirements and what the json is used for, say sending data between angular and php, then the coder is usually in control of both front end and backend and can use what ever json format they want, but it's different when you have to follow an API, but usually you can get support from the API owner and payment services tend to also do a verification round before letting you to use production grade transactions. -- //Aho
[toc] | [prev] | [next] | [standalone]
| From | doctor@doctor.nl2k.ab.ca (The Doctor) |
|---|---|
| Date | 2023-03-05 00:52 +0000 |
| Message-ID | <tu0p47$29gl$4@gallifrey.nk.ca> |
| In reply to | #19369 |
In article <k6i6l8FksscU2@mid.individual.net>, J.O. Aho <user@example.net> wrote: >On 3/5/23 00:58, The Doctor wrote: >> J.O. Aho <user@example.net> wrote: > >> : https://pastebin.com/bF6bZseu >> : Keep in mind nothin is a 100% solution for your issue as I haven't >> : bothered really go into the API that is used but just a bit based on >> : your posts in this group. >> >> : And please, what ever you do, don't go with the str_replace, it's not >> : the solution to your issue, it will just make things a lot harder to >> : maintain. >> >> >> Actually the class approach works better. > >That's good, just tweak it to fit your user case, just don't forget >validate the input data. > > >> Too bad Google does not pick that up >> in their searches for JSON> > >Much depends on the requirements and what the json is used for, say >sending data between angular and php, then the coder is usually in >control of both front end and backend and can use what ever json format >they want, but it's different when you have to follow an API, but >usually you can get support from the API owner and payment services tend >to also do a verification round before letting you to use production >grade transactions. > A good article can be written about this. >-- > //Aho > -- Member - Liberal International This is doctor@nk.ca Ici doctor@nk.ca Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising! Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b We cannot defy gravity without paying a price. -unknown Beware https://mindspring.com
[toc] | [prev] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2023-03-05 12:16 +0100 |
| Message-ID | <k6jc0rFpvrcU1@mid.individual.net> |
| In reply to | #19370 |
On 3/5/23 01:52, The Doctor wrote: > In article <k6i6l8FksscU2@mid.individual.net>, > J.O. Aho <user@example.net> wrote: >> On 3/5/23 00:58, The Doctor wrote: >>> J.O. Aho <user@example.net> wrote: >> >>> : https://pastebin.com/bF6bZseu >>> : Keep in mind nothin is a 100% solution for your issue as I haven't >>> : bothered really go into the API that is used but just a bit based on >>> : your posts in this group. >>> >>> : And please, what ever you do, don't go with the str_replace, it's not >>> : the solution to your issue, it will just make things a lot harder to >>> : maintain. >>> >>> >>> Actually the class approach works better. >> >> That's good, just tweak it to fit your user case, just don't forget >> validate the input data. >> >> >>> Too bad Google does not pick that up >>> in their searches for JSON> >> >> Much depends on the requirements and what the json is used for, say >> sending data between angular and php, then the coder is usually in >> control of both front end and backend and can use what ever json format >> they want, but it's different when you have to follow an API, but >> usually you can get support from the API owner and payment services tend >> to also do a verification round before letting you to use production >> grade transactions. >> > > A good article can be written about this. Great, post the link when you have written it ;) It's about time, to write a good example that make sense without bad coding and then host and promote the page, not everyone is prepared to do that. Sadly we see a lot of cheap cut the corner stuff out on the net, much for people have sample with simple structures so arrays works ok, but that is much based on the quality of the education they had. For example there is a country that spits out 2 million CS each year, many of them have a skills level not much than general high school students programing knowledge level. Should also note that there are really good programmers from that country too. The main thing is that you get forward on your project. -- //Aho
[toc] | [prev] | [next] | [standalone]
| From | The Doctor <doctor@doctor.nl2k.ab.ca> |
|---|---|
| Date | 2023-03-05 14:08 +0000 |
| Message-ID | <tu27ov$2dt5$126@gallifrey.nk.ca> |
| In reply to | #19371 |
J.O. Aho <user@example.net> wrote: : On 3/5/23 01:52, The Doctor wrote: : > In article <k6i6l8FksscU2@mid.individual.net>, : > J.O. Aho <user@example.net> wrote: : >> On 3/5/23 00:58, The Doctor wrote: : >>> J.O. Aho <user@example.net> wrote: : >> : >>> : https://pastebin.com/bF6bZseu : >>> : Keep in mind nothin is a 100% solution for your issue as I haven't : >>> : bothered really go into the API that is used but just a bit based on : >>> : your posts in this group. : >>> : >>> : And please, what ever you do, don't go with the str_replace, it's not : >>> : the solution to your issue, it will just make things a lot harder to : >>> : maintain. : >>> : >>> : >>> Actually the class approach works better. : >> : >> That's good, just tweak it to fit your user case, just don't forget : >> validate the input data. : >> : >> : >>> Too bad Google does not pick that up : >>> in their searches for JSON> : >> : >> Much depends on the requirements and what the json is used for, say : >> sending data between angular and php, then the coder is usually in : >> control of both front end and backend and can use what ever json format : >> they want, but it's different when you have to follow an API, but : >> usually you can get support from the API owner and payment services tend : >> to also do a verification round before letting you to use production : >> grade transactions. : >> : > : > A good article can be written about this. : Great, post the link when you have written it ;) : It's about time, to write a good example that make sense without bad : coding and then host and promote the page, not everyone is prepared to : do that. : Sadly we see a lot of cheap cut the corner stuff out on the net, much : for people have sample with simple structures so arrays works ok, but : that is much based on the quality of the education they had. For example : there is a country that spits out 2 million CS each year, many of them : have a skills level not much than general high school students : programing knowledge level. Should also note that there are really good : programmers from that country too. : The main thing is that you get forward on your project. Wait until you see the nightmare in bureaucracy. -- Member - Liberal International This is doctor@nk.ca Ici doctor@nk.ca Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising! Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b We cannot defy gravity without paying a price. -unknown Beware https://mindspring.com
[toc] | [prev] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2023-03-06 09:30 +0100 |
| Subject | Re: Bureaucracy (Was: Replace punctuation in an associative array) |
| Message-ID | <k6lmkuF6nvgU1@mid.individual.net> |
| In reply to | #19372 |
On 3/5/23 15:08, The Doctor wrote: > J.O. Aho <user@example.net> wrote: > : The main thing is that you get forward on your project. > > Wait until you see the nightmare in bureaucracy. If there is a bureaucracy, then the solution would be to go behinfd their backs and just show look it works without mentioning how. This change shoulld go past a review, specially when it makes the code more understandable. The most problematic one is if you have someone who has slight code skill in the Opration team that will deploy the code and thinks he should take a look at the code before clearing it for deployment, then you may have issues. There I don't have a good advice than be presistant and tell the this change will make it easier for him as there will be less deployments due of faulty code. -- //Aho
[toc] | [prev] | [next] | [standalone]
| From | The Doctor <doctor@doctor.nl2k.ab.ca> |
|---|---|
| Date | 2023-03-07 16:43 +0000 |
| Message-ID | <tu7pim$1i39$55@gallifrey.nk.ca> |
| In reply to | #19372 |
The Doctor <doctor@doctor.nl2k.ab.ca> wrote: : J.O. Aho <user@example.net> wrote: : : On 3/5/23 01:52, The Doctor wrote: : : > In article <k6i6l8FksscU2@mid.individual.net>, : : > J.O. Aho <user@example.net> wrote: : : >> On 3/5/23 00:58, The Doctor wrote: : : >>> J.O. Aho <user@example.net> wrote: : : >> : : >>> : https://pastebin.com/bF6bZseu : : >>> : Keep in mind nothin is a 100% solution for your issue as I haven't : : >>> : bothered really go into the API that is used but just a bit based on : : >>> : your posts in this group. : : >>> : : >>> : And please, what ever you do, don't go with the str_replace, it's not : : >>> : the solution to your issue, it will just make things a lot harder to : : >>> : maintain. : : >>> : : >>> : : >>> Actually the class approach works better. : : >> : : >> That's good, just tweak it to fit your user case, just don't forget : : >> validate the input data. : : >> : : >> : : >>> Too bad Google does not pick that up : : >>> in their searches for JSON> : : >> : : >> Much depends on the requirements and what the json is used for, say : : >> sending data between angular and php, then the coder is usually in : : >> control of both front end and backend and can use what ever json format : : >> they want, but it's different when you have to follow an API, but : : >> usually you can get support from the API owner and payment services tend : : >> to also do a verification round before letting you to use production : : >> grade transactions. : : >> : : > : : > A good article can be written about this. : : Great, post the link when you have written it ;) : : It's about time, to write a good example that make sense without bad : : coding and then host and promote the page, not everyone is prepared to : : do that. : : Sadly we see a lot of cheap cut the corner stuff out on the net, much : : for people have sample with simple structures so arrays works ok, but : : that is much based on the quality of the education they had. For example : : there is a country that spits out 2 million CS each year, many of them : : have a skills level not much than general high school students : : programing knowledge level. Should also note that there are really good : : programmers from that country too. : : The main thing is that you get forward on your project. : Wait until you see the nightmare in bureaucracy. Other nightmare, I might have to write a preview page. -- Member - Liberal International This is doctor@nk.ca Ici doctor@nk.ca Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising! Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b Fools presume to know all; the wise know they do not. -unknown Beware https://mindspring.com
[toc] | [prev] | [next] | [standalone]
Page 1 of 3 [1] 2 3 Next page →
Back to top | Article view | comp.lang.php
csiph-web