Jump to content

select if in a long text char line


Monkuar

Recommended Posts

Code:

 

PostInfo,color-main,Newman,not-collapsed;Friends,color-main2,Top Friends,not-collapsed||Twitter,color-main2,Twitter,not-collapsed;Signature,color-main2,Signature,not-collapsed;AboutMe,color-transparent,About Me,not-collapsed

 

 

Now I want make a function like

 

if PostInfo = "not-collapsed" = do this/etc,

 

 

So simply, how do I extract some content out of this and then use each thing to equal to if it's 'not-collapsed' or 'collapsed' ?

 

Very hard but i think possible? ty

Link to comment
https://forums.phpfreaks.com/topic/254535-select-if-in-a-long-text-char-line/
Share on other sites

If it was in a completely consistent format, you might have a chance, but as it is right now, I don't see how you could effectively do it.

 

 

well im trying to spit them out by explode with ,  but theres going to be to many if's

Maybe you can take a look at this to see if it will work for you or if there is something you can build off of it :

 

//the original string
$string = 'PostInfo,color-main,Newman,not-collapsed;Friends,color-main2,Top Friends,not-collapsed||Twitter,color-main2,Twitter,not-collapsed;Signature,color-main2,Signature,not-collapsed;AboutMe,color-transparent,About Me,not-collapsed';

//could be wrong but seems like this should just be a semi-colon 
$string = str_replace('||',';',$string);

//explode them by the ; as it seems that is the separator of the content
$ex_string = explode(';',$string);

//count them (faster than doing it in the loop)
$ex_count = count($ex_string);

//loop through each of the sets
for($i=0;$i<$ex_count;$i++){
//now you can explode them on the comma to get there data
$ex_string[$i] = explode(',',$ex_string[$i]);

//you can either check the data here
if($ex_string[$i][0] == 'PostInfo' && $ex_string[$i][3] == 'not-collapsed'){
	//it is not collapsed so do something
}
}

//print it out so you can see the data
print_r($ex_string);

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.