I've played and confused.
I have decided to post up what works and what doesn't an expanding the code.
The original code which worked by identifying http://localhost was as follows:
$multiLinks = array();
foreach ( $matches[0] as $k => $match ) {
if ( $post->multiurl_token ) {
if ( strpos($matches[2][$k], 'http://localhost') === false ) {
$multiLinks[$matches[2][$k]] = $matches[3][$k];
}
}
else {
$multiLinks[$matches[2][$k]] = $matches[3][$k];
}
}
Followed by a further piece of code a little later:
if ( $data ) {
$data = json_decode($data);
if ( isset($data->token) && $data->token ) {
if ( isset($data->links) && $data->links ) {
$newlinks = array();
foreach ( $data->links as $link ) {
$newlinks[$link->original_url] = $link->short_url;
}
foreach ( $matches[0] as $k => $match ) {
if ( strpos($match, 'http://localhost') === false ) {
$newlink = $match;
$newlink = str_replace($matches[2][$k], $newlinks[$matches[2][$k]], $newlink);
$content = str_replace($match, $newlink, $content);
}
}
}
With http://localhost or http://mysite.com in both parts the URLs are recognised and treated accordingly.
The first permutation I tried is by adding OR into the first section of code:
$multiLinks = array();
foreach ( $matches[0] as $k => $match ) {
if ( $post->multiurl_token ) {
if ( strpos($matches[2][$k], 'http://mysite.com') === false || strpos($matches[2][$k], 'http://localhost') === false) {
$multiLinks[$matches[2][$k]] = $matches[3][$k];
}
}
else {
$multiLinks[$matches[2][$k]] = $matches[3][$k];
}
}
and leaving the second part unchanged.
This does not work and neither http://mysite.com or http://localhost are recognised.
However, if I change the second part to:
if ( $data ) {
$data = json_decode($data);
if ( isset($data->token) && $data->token ) {
if ( isset($data->links) && $data->links ) {
$newlinks = array();
foreach ( $data->links as $link ) {
$newlinks[$link->original_url] = $link->short_url;
}
foreach ( $matches[0] as $k => $match ) {
if ( strpos($match, 'http://mysite.com') === false) {
$newlink = $match;
$newlink = str_replace($matches[2][$k], $newlinks[$matches[2][$k]], $newlink);
$content = str_replace($match, $newlink, $content);
}
}
}
i.e. change http://localhost to http://mysite.com it recognises anything that is http://mysite.com and treats it accordingly.
If I change the second part to include an OR i.e.
if ( $data ) {
$data = json_decode($data);
if ( isset($data->token) && $data->token ) {
if ( isset($data->links) && $data->links ) {
$newlinks = array();
foreach ( $data->links as $link ) {
$newlinks[$link->original_url] = $link->short_url;
}
foreach ( $matches[0] as $k => $match ) {
if ( strpos($match, 'http://mysite.com') === false) || strpos($match, 'http://localhost') === false) {
$newlink = $match;
$newlink = str_replace($matches[2][$k], $newlinks[$matches[2][$k]], $newlink);
$content = str_replace($match, $newlink, $content);
}
}
}
I get the following error:
Parse error: syntax error, unexpected T_BOOLEAN_OR
Any help really appreciated.
Thanks
Mark