Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3919

Break $content into array when conditions are met

$
0
0

I have an array with Category names $categories_array.
I have a $content variable containing a big string (product description)

My intention is to explode $content into an array ($content_array).
That is easy.
The content also contains category names on itThe problem is as follows:

  • category is named Kids and Baby

I cant explode by word, as I want to keep the content kids and baby in the same array entry.
I also cant query all the time as it would be resource expensive.

What is the best way to achieve something like this:

This is the original $content:

$content = "lorem ipsum bla bla bla cat1 bla bla bla kids and baby";

This is my categories array:

$categories_array = array("cat1","kids and baby","cat3",    ...);

This is my expected output:

$content_array = array("word1","word2","kids and baby","word3");

Thank you for your guidance.


Viewing all articles
Browse latest Browse all 3919

Trending Articles