My goal is to end up with an array.... During my testing I use strings of code it works, but I am unable to use the explode function as I was expecting? Can anyone explain what I am doing wrong?

This outputs my goal

$half_string = "MONMOUTH: 37 WAGNER: 41 17:57 2nd Half";

$string_half = substr_replace("$half_string"," ",-14);
print_r(explode(":",$string_half));


// $final_string is a test
$final_string = "NEW MEXICO: 77 SAN DIEGO ST: 67 FINAL";

$string_final = substr_replace("NEW MEXICO: 77 SAN DIEGO ST: 67 FINAL"," ",-5);
print_r(explode(":",$string_final));

This works in terms of the code not breaking but it's not what I am looking for because it's a string

function user_sub_home_page(){
  $output = NULL;
  $s_id = arg(1); //current odds info
  $snode = node_load($s_id);
  
  $half_string = $snode -> field_h_string_score ['und']['0']['value'];
  

$string_half = substr_replace("$half_string"," ",-14);
(explode(":",$string_half));
    
print_r ($string_half);
  
}

To see how this output appeared it is posted here http://drupal.org/node/1441750

Comments

jaypan’s picture

You haven't told us what you are trying to do. You also haven't told us how it's not working. You made one statement and added a question mark after it, which doesn't exactly make it into a question. Then you asked us what you were doing wrong, but how are we supposed to know without knowing what you were intending to do?

Contact me to contract me for D7 -> D10/11 migrations.
Or anything really. I'm friendly, and open to work or conversation.

otcassetmgmt’s picture

My goal is to end up with an array.... If I copy and paste the string into my explode function it does output and array, but when pulling my string from an object node to preform the explosion function it outputs another string.

I receive the strings originality as emails (this is the only way I get the data) which are posted as XML feeds then using the feeds module I import those strings and filter through them all strings are filtered in the code I am trying to create.

I hope this makes since I am not a great writer.

jaypan’s picture

What should the array that you are trying to create look like?

Contact me to contract me for D7 -> D10/11 migrations.
Or anything really. I'm friendly, and open to work or conversation.

otcassetmgmt’s picture

Array ( [0] => MONMOUTH [1] => 37 WAGNER [2] => 41 )

jaypan’s picture

$half_string = "MONMOUTH: 37 WAGNER: 41 17:57 2nd Half";
preg_match('/^([a-zA-Z ]+): (\d+) ([a-zA-Z ]+): (\d+)/', $half_string, $matches);
$values = array();
if(isset($matches[1]))
{
  for($i = 0; $i < 5; $i++)
  {
    $values[$i] = $matches[$i+i];
  }
}

Your array is $values. You can skip the $values array and work off the $matches array as well, just realize that $matches[0] will be the original string.

Contact me to contract me for D7 -> D10/11 migrations.
Or anything really. I'm friendly, and open to work or conversation.