My Code is working fine but somehow Yourls is getting only the first Word of the Site Title. It does not forward anything after the space of the first Word.
The Code
$Artikel = $smarty->get_template_vars('Artikel');
$keyword = $Artikel->cArtNr;
$title = $Artikel->cName;
$short = file_get_contents(''.$siteurl.'/yourls-api.php?signature='.$signature.'&action=shorturl&url='.$shorturl.'&format='.$format.'&keyword='.$keyword.'&title='.$title.'');
If the Title is "My first Computer" than only "My" is set as Title. Is it cause my Code or Yourls?
The issue is likely related to URL character encoding. You are not encoding the space in $title
, rendering the URI invalid.
You can use urlencode
to perform this on your query string arguments, but it may be easier and better to refactor your code to use http_build_query
:
$query = http_build_query(array(
'signature' => $signature,
'action' => 'shorturl',
'url' = $shorturl,
'format' => $format,
'keyword' => $keyword,
'title' => $title
));
file_get_contents($siteurl . '/yourls-api.php?' . $query);