simona6 Posted February 21, 2020 Share Posted February 21, 2020 Quote #adf #234432 #fwerfw I have this as a result of a form that has been completed. It might be twice that, it might be much much more. But what I want to do is render it on a page inside Divs. So each one is in a kind of shaded box. The CSS side of it is easy, but how do I extract each one of these into a variable useful means to surround each one by <div>$variable</div>? I thought it might be "explode", but you appear to have to state the [3] number of the variable to show. In this case, it's totally random. We won't be using these as Variables to trigger anything else, it's purely "for display" purposes. Quote Link to comment Share on other sites More sharing options...
chhorn Posted February 21, 2020 Share Posted February 21, 2020 So how should the array look like then? Quote Link to comment Share on other sites More sharing options...
simona6 Posted February 21, 2020 Author Share Posted February 21, 2020 That is what I am asking here. I don't even know of explode() is the right method. All I know is that I need to split them up, to show each one in an individual DIV, but they are entered in a text box. Quote Link to comment Share on other sites More sharing options...
chhorn Posted February 21, 2020 Share Posted February 21, 2020 If you don't know what to achieve, how should we? did you try to explode that string? is that the result you wanted? split the string up by what, with what result? Quote Link to comment Share on other sites More sharing options...
simona6 Posted February 21, 2020 Author Share Posted February 21, 2020 (edited) I have the content in, let's say $hastags. I want to split that content so it starts at the #, and ends at the space. I'm asking of the best way to do this - it might not be explode(). Trouble is, when I have seen that used, it's usually numbered, and if you don't know how many there will be, how do you know how many arrays to look at? <?php $mystr='I like Programming'; //space is used as delimiter $parts=explode(' ', $mystr); echo $parts[0] . '<br/>'; echo $parts[1] . '<br/>'; echo $parts[2]; ?> Here is an example. But what if there are 15 terms in here to be split up. How do you manage that, dynamically? One might have 15, one might have just 2. I can of course easily put them into variables, and the answer might be as a 'count'. Edited February 21, 2020 by simona6 Quote Link to comment Share on other sites More sharing options...
Barand Posted February 21, 2020 Share Posted February 21, 2020 try $hashtags = '#adf #234432 #fwerfw'; $array = explode(' ', $hashtags); foreach ($array as $var) { echo "<div style='width: 200px; border: 1px solid red; margin: 8px; padding: 8px'>$var</div>"; } Quote Link to comment Share on other sites More sharing options...
simona6 Posted February 21, 2020 Author Share Posted February 21, 2020 Answered my own question.... //space is used as delimiter $parts=explode(' ', $row->uniquehashtag); echo count($parts); echo $parts[0] . '<br/>'; echo $parts[1] . '<br/>'; echo $parts[2]; 'count' shows how many there are, then I can put those [0] arrays into a loop by the amount of count. Quote Link to comment Share on other sites More sharing options...
simona6 Posted February 21, 2020 Author Share Posted February 21, 2020 1 minute ago, Barand said: try $hashtags = '#adf #234432 #fwerfw'; $array = explode(' ', $hashtags); foreach ($array as $var) { echo "<div style='width: 200px; border: 1px solid red; margin: 8px; padding: 8px'>$var</div>"; } Ooo I like that method too. Quote Link to comment Share on other sites More sharing options...
simona6 Posted February 21, 2020 Author Share Posted February 21, 2020 $hashtags = strip_tags($row->uniquehashtag); $array = explode(' ', $hashtags); foreach ($array as $tag) { echo "<span class='gig-hashtags'>$tag</span>"; } Spot on - removes the <p> tag in the code too! Plus anything else they might have added. Thanks everyone. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.