Question: I have a function that has data which is a combination of promise data and simple math values. Here's the function : 

```
_getTotalPrice = function() {

            var price = 0;
            // Simple Math data.
            // Calculate price for channels first. 
            price = price + ( num_channels - 5 )*( 4);

            var themepacks = cart.themepacks;
            if(themepacks) {
                angular.forEach(themepacks, function(pack, index) {

                // data coming from a service
                channelFactory.getThemePack(pack).then(function(result) {
                    price = price + Number(result.packPriceAmt);
                    console.log("price", price);
                  });
              });
            }

          console.log(" Total price", price);
          return price; 
 };

```

At the time of page load, the value of `Total price` and `price` is different. It is because the `price` is loaded after promise is resolved. How can I wait till the promise is resolved before returning the value? Do I create another promise within this function?

Answer: 
I'm not sure this is the best solution for this case.
But it's worked for me.

```
<?php
function get_title($url){
  $str = file_get_contents($url);
  if(strlen($str)>0){
    $str = trim(preg_replace('/\s+/', ' ', $str)); // supports line breaks inside <title>
    preg_match("/\<title\>(.*?)\<\/title\>/i",$str,$title); // ignore case
    return $title[1];
  }
}

$url = @$_SERVER[HTTP_REFERER];
echo "<a href='$url'>Back to ".get_title($url)."</a>";
?>

```

Result

[![enter image description here](https://i.stack.imgur.com/oJNCc.png)](https://i.stack.imgur.com/oJNCc.png)
You could try like this:

```
$html = file_get_contents($url);
preg_match_all('/<title>(.*?)<\/title>/s', $html, $matches);
print_r($matches[1]);

```