peps03
asked on
Stripping out some text out of piece of code
Hi,
This piece of code:
if(isset($SEARCH)){
$NAVIGATION->outputPageTit le($SEARCH );
}else{
$NAVIGATION->outputPageTit le();
}
outputs:
<title> xxxxxxxx </title>
+
<meta name="description" content="yyyyyyyyyyyyyyyy" />
i would like to modify the code above to only output "xxxxxxx" (also without the title-tags)
is that possible in a way?
thanks
This piece of code:
if(isset($SEARCH)){
$NAVIGATION->outputPageTit
}else{
$NAVIGATION->outputPageTit
}
outputs:
<title> xxxxxxxx </title>
+
<meta name="description" content="yyyyyyyyyyyyyyyy"
i would like to modify the code above to only output "xxxxxxx" (also without the title-tags)
is that possible in a way?
thanks
ps: I've added the single quotes to show that the space has been removed in this example
ASKER
Thanks for you reaction Darren-w,
but this is the code that needs the modifying:
if(isset($SEARCH)){
$NAVIGATION->outputPageTit le($SEARCH );
}else{
$NAVIGATION->outputPageTit le();
}
(so it only outputs xxxxxxxxx)
you are modifying the output.
but this is the code that needs the modifying:
if(isset($SEARCH)){
$NAVIGATION->outputPageTit
}else{
$NAVIGATION->outputPageTit
}
(so it only outputs xxxxxxxxx)
you are modifying the output.
Can you show us the code in the method 'outputPageTitle'
Also Peps03, I think darren-w may have been just trying to show you what to change within your method - it seems like that's where you may want to make your changes.
ASKER
Sure.
what i'm trying is also using the title text as the site banners alt-text.
so i can't really mess around in the code below, as it creates the page title and meta description
what i'm trying is also using the title text as the site banners alt-text.
so i can't really mess around in the code below, as it creates the page title and meta description
<?
public function outputPageTitle($search=null){
switch($this->getType()){
case NAVIGATION_NORMAL:
$meta = "";
echo "<title>";
if($this->hasObject()){
$oId = $this->object();
$city = getObjectField($oId, "plaats");
if(is_numeric($city)){
$city = getObjectField($city, "naam");
}
$title = htmlentities( getObjectField($oId, "adres") .", ". $city);
$detail = $this->activeDetail();
switch( $detail){
case DETAIL_FOTO:
echo "Foto's van kantoorruimte ". $title ." - KantoorBalie.nl";
break;
case DETAIL_MAP;
echo "Bekijk de ligging van kantoorruimte ". $title ." op de kaart - KantoorBalie.nl";
break;
default:
echo "Kantoorruimte huren ". $title ."? Bij KantoorBalie.nl kunt u kantoorruimte huren ". $title;
break;
}
}else if($this->plaats() != ""){
$pp = $this->parsedPlaats();
echo "Kantoorruimte huren in ". $pp ."? Bedrijfsruimte te huur in ". $pp;
}else if($this->provincie() != ""){
$r = $this->parsedProvincie();
echo "Kantoorruimte huren in ". $r ."? Bedrijfsruimte te huur in ". $r;
}else if($this->tag() != ""){
$ids = getObjectIdByTemplateFieldValue("tag", "permanente link", $this->tag());
if(count($ids) > 0){
echo getObjectField($ids[0], "pagina titel");
}else{
echo "Informatie over '". $this->parsedTag() ."' op Kantoorbalie.nl";
}
}else{
$detail = $this->activeDetail();
switch($detail){
case DETAIL_CITIES:
echo "Bekijk ons kantoorruimte aanbod per stad op de kaart - KantoorBalie.nl";
break;
case DETAIL_PROVINCES:
echo "Bekijk ons kantoorruimte aanbod per provincie op de kaart - KantoorBalie.nl";
break;
default:
$fId = $this->getActiveContentId();
if( $fId != -1){
$s = getStructureById($fId);
$c = getObjectCount($s, "pagina metadata");
if($c > 0){
$id = getObjectId($s, 0, "pagina metadata");
$title = getObjectField($id, "titel");
$meta = getObjectField($id, "metadata");
if($title != ""){
echo $title;
}else{
echo getStructureNameById($fId) ." - Kantoorbalie.nl";
}
}else{
echo getStructureNameById($fId) ." - Kantoorbalie.nl";
}
}
}
}
echo "</title>".PHP_EOL;
if($meta != ""){
echo '<meta name="description" content="'. htmlentities($meta) .'" />'.PHP_EOL;
}
break;
case NAVIGATION_SEARCH:
echo "<title>";
if(isset($search)){
$criteria = $search->getCriteria();
if($criteria["plaatsId"] != -1){
$pp = getObjectField($criteria["plaatsId"], "naam");
echo "Kantoorruimte huren in ". $pp ."? Bij KantoorBalie.nl kunt u kantoorruimte huren in ". $pp;
}else if($criteria["plaats"] != ""){
echo "Kantoorruimte huren in ". $criteria["plaats"] ."? Bij KantoorBalie.nl kunt u kantoorruimte huren in ". $criteria["plaats"];
}
}
echo "</title>".PHP_EOL;
break;
case NAVIGATION_RSS:
break;
}
}
?>
yes,
so in the method outputPageTitle();
the last line might say something like
return $title;
you would need to change it like:
return trim(strip_tags($title));
so in the method outputPageTitle();
the last line might say something like
return $title;
you would need to change it like:
return trim(strip_tags($title));
ASKER
yes, but if i change the source, the page will also lose its title tags
Humm,
you need to overload your method with a boolean switch to show or not show title,
then in the code you need initially create a variable for title, and append the text to it as opposed to echoing it.
finally you should echo the variable you have built up, with or without the title tags dependant on the boolean value
ie
if ($showtitle)
{
echo $title;}
else{
echo trim(strip_tags($title));
}
you need to overload your method with a boolean switch to show or not show title,
then in the code you need initially create a variable for title, and append the text to it as opposed to echoing it.
finally you should echo the variable you have built up, with or without the title tags dependant on the boolean value
ie
if ($showtitle)
{
echo $title;}
else{
echo trim(strip_tags($title));
}
dammit darren ... beat me to it .. lol
ASKER
thanks Darren ;)
but excuse me for not understanding right away. where would i have to make these changes?
i have the big piece of code that generates the <titke> and the <meta>
and the small piece that displays both
the third piece that (has to be created?) should only echo xxxxxx
thanks!
but excuse me for not understanding right away. where would i have to make these changes?
i have the big piece of code that generates the <titke> and the <meta>
and the small piece that displays both
the third piece that (has to be created?) should only echo xxxxxx
thanks!
peps03,
The changes need to be done in your code, there is a lot going on in this method; its also very complex, and could it do with being broken down into further methods for ease of reading, also I would recommend that you build the meta and title tags into a string variable and then echo their value at the end, when you have done this you can isolate the text as in my example or add the title tags at the end, and not add them in the code.
Darren
The changes need to be done in your code, there is a lot going on in this method; its also very complex, and could it do with being broken down into further methods for ease of reading, also I would recommend that you build the meta and title tags into a string variable and then echo their value at the end, when you have done this you can isolate the text as in my example or add the title tags at the end, and not add them in the code.
Darren
ASKER
oke.. wouldn't really know how to do that.
isn't it just possible to "capture" the <title> out of this code:
if(isset($SEARCH)){
$NAVIGATION->outputPageTit le($SEARCH );
}else{
$NAVIGATION->outputPageTit le();
}
and then strip of the tag?
or get the title after it is echoed to the page? and then strip it out?
i also tried removing the title tags from the long code, and echoing it between self added <title> tags in the header, but then the <meta> tag also gets stuck in the title tag..
is there an easy way of maybe splitting the title and the meta tag? so i can echo the title between the (self added) title tags in the header (and the title text in the alt of the banner)
and then the meta-tag separately below it?
isn't it just possible to "capture" the <title> out of this code:
if(isset($SEARCH)){
$NAVIGATION->outputPageTit
}else{
$NAVIGATION->outputPageTit
}
and then strip of the tag?
or get the title after it is echoed to the page? and then strip it out?
i also tried removing the title tags from the long code, and echoing it between self added <title> tags in the header, but then the <meta> tag also gets stuck in the title tag..
is there an easy way of maybe splitting the title and the meta tag? so i can echo the title between the (self added) title tags in the header (and the title text in the alt of the banner)
and then the meta-tag separately below it?
maybe add another method along the lines of
echoString($string,$type=n ull){
switch($type){
case "title":
echo "<title>".trim($string)."< /title>";
break;
case "meta":
echo "<meta>".trim($string)."</ meta>";
break;
default:
echo trim(strip_tags($title));
break;
}
}
Then on your echos in the current method, replace
echo "random string data";
with:
$this->echoString("random string data","title"); //where title can be title, meta, or nothing for no tags ..
echoString($string,$type=n
switch($type){
case "title":
echo "<title>".trim($string)."<
break;
case "meta":
echo "<meta>".trim($string)."</
break;
default:
echo trim(strip_tags($title));
break;
}
}
Then on your echos in the current method, replace
echo "random string data";
with:
$this->echoString("random string data","title"); //where title can be title, meta, or nothing for no tags ..
Hi,
Once the text has been echoed to the browser there is no way to edit with php.
dependant on how you intend to use the code you could extract it from the body with JQuery
echo $("title").text())
take this value and put it into a div on the page
$("#titletext").text($("ti tle").text ())
<div id="titletext"></div>
Once the text has been echoed to the browser there is no way to edit with php.
dependant on how you intend to use the code you could extract it from the body with JQuery
echo $("title").text())
take this value and put it into a div on the page
$("#titletext").text($("ti
<div id="titletext"></div>
ASKER
this is getting closer to what i am looking for.
can the extracted text only be put in a div, or also in the alt-text?
can the extracted text only be put in a div, or also in the alt-text?
How about setting the string value to a variable:
if(isset($SEARCH)){
$mytext = $NAVIGATION->outputPageTit le($SEARCH );
}else{
$mytext = $NAVIGATION->outputPageTit le();
}
// just checking
//echo $mytext;
$mytext = str_replace("<title>","",$ mytext);
$mytext = str_replace("</title>","", $mytext);
// double checking
echo $mytext;
if(isset($SEARCH)){
$mytext = $NAVIGATION->outputPageTit
}else{
$mytext = $NAVIGATION->outputPageTit
}
// just checking
//echo $mytext;
$mytext = str_replace("<title>","",$
$mytext = str_replace("</title>","",
// double checking
echo $mytext;
ASKER
@ Roads
it is still outputting the normal:
<title> xxx </title>
<meta yyyyyyy />
it is still outputting the normal:
<title> xxx </title>
<meta yyyyyyy />
Putting it in alt text on a hyperlink with a I
Id of linkref
$('a#linkref').attr('alt', $('title') .text())
Id of linkref
$('a#linkref').attr('alt',
Well, if you need to output only the "inside stuff", comment out the lines with echo title:
public function outputPageTitle($search=null){
switch($this->getType()){
case NAVIGATION_NORMAL:
$meta = "";
//echo "<title>";
if($this->hasObject()){
$oId = $this->object();
$city = getObjectField($oId, "plaats");
if(is_numeric($city)){
$city = getObjectField($city, "naam");
}
$title = htmlentities( getObjectField($oId, "adres") .", ". $city);
$detail = $this->activeDetail();
switch( $detail){
case DETAIL_FOTO:
echo "Foto's van kantoorruimte ". $title ." - KantoorBalie.nl";
break;
case DETAIL_MAP;
echo "Bekijk de ligging van kantoorruimte ". $title ." op de kaart - KantoorBalie.nl";
break;
default:
echo "Kantoorruimte huren ". $title ."? Bij KantoorBalie.nl kunt u kantoorruimte huren ". $title;
break;
}
}else if($this->plaats() != ""){
$pp = $this->parsedPlaats();
echo "Kantoorruimte huren in ". $pp ."? Bedrijfsruimte te huur in ". $pp;
}else if($this->provincie() != ""){
$r = $this->parsedProvincie();
echo "Kantoorruimte huren in ". $r ."? Bedrijfsruimte te huur in ". $r;
}else if($this->tag() != ""){
$ids = getObjectIdByTemplateFieldValue("tag", "permanente link", $this->tag());
if(count($ids) > 0){
echo getObjectField($ids[0], "pagina titel");
}else{
echo "Informatie over '". $this->parsedTag() ."' op Kantoorbalie.nl";
}
}else{
$detail = $this->activeDetail();
switch($detail){
case DETAIL_CITIES:
echo "Bekijk ons kantoorruimte aanbod per stad op de kaart - KantoorBalie.nl";
break;
case DETAIL_PROVINCES:
echo "Bekijk ons kantoorruimte aanbod per provincie op de kaart - KantoorBalie.nl";
break;
default:
$fId = $this->getActiveContentId();
if( $fId != -1){
$s = getStructureById($fId);
$c = getObjectCount($s, "pagina metadata");
if($c > 0){
$id = getObjectId($s, 0, "pagina metadata");
$title = getObjectField($id, "titel");
$meta = getObjectField($id, "metadata");
if($title != ""){
echo $title;
}else{
echo getStructureNameById($fId) ." - Kantoorbalie.nl";
}
}else{
echo getStructureNameById($fId) ." - Kantoorbalie.nl";
}
}
}
}
//echo "</title>".PHP_EOL;
if($meta != ""){
echo '<meta name="description" content="'. htmlentities($meta) .'" />'.PHP_EOL;
}
break;
case NAVIGATION_SEARCH:
//echo "<title>";
if(isset($search)){
$criteria = $search->getCriteria();
if($criteria["plaatsId"] != -1){
$pp = getObjectField($criteria["plaatsId"], "naam");
echo "Kantoorruimte huren in ". $pp ."? Bij KantoorBalie.nl kunt u kantoorruimte huren in ". $pp;
}else if($criteria["plaats"] != ""){
echo "Kantoorruimte huren in ". $criteria["plaats"] ."? Bij KantoorBalie.nl kunt u kantoorruimte huren in ". $criteria["plaats"];
}
}
//echo "</title>".PHP_EOL;
break;
case NAVIGATION_RSS:
break;
}
}
... and just use:
if(isset($SEARCH)){
$NAVIGATION->outputPageTit le($SEARCH );
}else{
$NAVIGATION->outputPageTit le();
}
if(isset($SEARCH)){
$NAVIGATION->outputPageTit
}else{
$NAVIGATION->outputPageTit
}
ASKER
@ roads, i tried that earlier, then it outputs the meta tag in the title
yes, if you need to delete it, just comment out that line (100):
// echo '<meta name="description" content="'. htmlentities($meta) .'" />'.PHP_EOL;
// echo '<meta name="description" content="'. htmlentities($meta) .'" />'.PHP_EOL;
ASKER
@ darren-w-:
how will the the jQuery code look like? i can't get it working..
i do have jquery version 1.2.6 installed..
how will the the jQuery code look like? i can't get it working..
i do have jquery version 1.2.6 installed..
ASKER
@ roads, as told above, these lines are needed to generate the sites title and meta, so i cant comment things out in the "large" code because then the site wont have a title and meta.
please read the earlier posts.
please read the earlier posts.
<html>
<head>
<title>test</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<style type="text/css">
</style>
<script type='text/javascript'>
$(function(){
$('img').attr('alt',$('title').text());
});
</script>
</head>
<body>
<img alt="" src="test.jpg">
</body>
</html>
Though, it may not be read by a screen reader, or spider
ASKER
darren-w-,
tried your example but the alt stays empty..
tried your example but the alt stays empty..
You won't see it in the source, you need To look in firebug or something similar, I can assure you that the value is set
ASKER
hmm oke, but i'm trying this to make a alt text that will be visible for spiders..
My php comments apply then sorry:(
OK, this code below is for testing. I did add mytitle inside a class, just for now it should work only for NAVIGATION_NORMAL case.
so after the code try yours like this
<?
var $mytitle = "";
public function outputPageTitle($search=null){
switch($this->getType()){
case NAVIGATION_NORMAL:
$meta = "";
echo "<title>";
if($this->hasObject()){
$oId = $this->object();
$city = getObjectField($oId, "plaats");
if(is_numeric($city)){
$city = getObjectField($city, "naam");
}
$title = htmlentities( getObjectField($oId, "adres") .", ". $city);
$detail = $this->activeDetail();
switch( $detail){
case DETAIL_FOTO:
echo "Foto's van kantoorruimte ". $title ." - KantoorBalie.nl";
$this->mytitle = "Foto's van kantoorruimte ". $title ." - KantoorBalie.nl";
break;
case DETAIL_MAP;
echo "Bekijk de ligging van kantoorruimte ". $title ." op de kaart - KantoorBalie.nl";
$this->mytitle = "Bekijk de ligging van kantoorruimte ". $title ." op de kaart - KantoorBalie.nl";
break;
default:
echo "Kantoorruimte huren ". $title ."? Bij KantoorBalie.nl kunt u kantoorruimte huren ". $title;
$this->mytitle = "Kantoorruimte huren ". $title ."? Bij KantoorBalie.nl kunt u kantoorruimte huren ". $title;
break;
}
}else if($this->plaats() != ""){
$pp = $this->parsedPlaats();
echo "Kantoorruimte huren in ". $pp ."? Bedrijfsruimte te huur in ". $pp;
$this->mytitle = "Kantoorruimte huren in ". $pp ."? Bedrijfsruimte te huur in ". $pp;
}else if($this->provincie() != ""){
$r = $this->parsedProvincie();
echo "Kantoorruimte huren in ". $r ."? Bedrijfsruimte te huur in ". $r;
$this->mytitle = "Kantoorruimte huren in ". $r ."? Bedrijfsruimte te huur in ". $r;
}else if($this->tag() != ""){
$ids = getObjectIdByTemplateFieldValue("tag", "permanente link", $this->tag());
if(count($ids) > 0){
echo getObjectField($ids[0], "pagina titel");
$this->mytitle = getObjectField($ids[0], "pagina titel");
}else{
echo "Informatie over '". $this->parsedTag() ."' op Kantoorbalie.nl";
$this->mytitle = "Informatie over '". $this->parsedTag() ."' op Kantoorbalie.nl";
}
}else{
$detail = $this->activeDetail();
switch($detail){
case DETAIL_CITIES:
echo "Bekijk ons kantoorruimte aanbod per stad op de kaart - KantoorBalie.nl";
$this->mytitle = "Bekijk ons kantoorruimte aanbod per stad op de kaart - KantoorBalie.nl";
break;
case DETAIL_PROVINCES:
echo "Bekijk ons kantoorruimte aanbod per provincie op de kaart - KantoorBalie.nl";
$this->mytitle = "Bekijk ons kantoorruimte aanbod per provincie op de kaart - KantoorBalie.nl";
break;
default:
$fId = $this->getActiveContentId();
if( $fId != -1){
$s = getStructureById($fId);
$c = getObjectCount($s, "pagina metadata");
if($c > 0){
$id = getObjectId($s, 0, "pagina metadata");
$title = getObjectField($id, "titel");
$meta = getObjectField($id, "metadata");
if($title != ""){
echo $title;
$this->mytitle = $title;
}else{
echo getStructureNameById($fId) ." - Kantoorbalie.nl";
$this->mytitle = getStructureNameById($fId) ." - Kantoorbalie.nl";
}
}else{
echo getStructureNameById($fId) ." - Kantoorbalie.nl";
$this->mytitle = getStructureNameById($fId) ." - Kantoorbalie.nl";
}
}
}
}
echo "</title>".PHP_EOL;
if($meta != ""){
echo '<meta name="description" content="'. htmlentities($meta) .'" />'.PHP_EOL;
}
break;
case NAVIGATION_SEARCH:
echo "<title>";
if(isset($search)){
$criteria = $search->getCriteria();
if($criteria["plaatsId"] != -1){
$pp = getObjectField($criteria["plaatsId"], "naam");
echo "Kantoorruimte huren in ". $pp ."? Bij KantoorBalie.nl kunt u kantoorruimte huren in ". $pp;
}else if($criteria["plaats"] != ""){
echo "Kantoorruimte huren in ". $criteria["plaats"] ."? Bij KantoorBalie.nl kunt u kantoorruimte huren in ". $criteria["plaats"];
}
}
echo "</title>".PHP_EOL;
break;
case NAVIGATION_RSS:
break;
}
}
public function showMyTitle(){
return $this->mytitle;
}
?>
so after the code try yours like this
if(isset($SEARCH)){
$NAVIGATION->outputPageTitle($SEARCH);
}else{
$NAVIGATION->outputPageTitle();
}
$test = showMyTitle();
echo "$test";
ASKER
Great thanks Roads_Roads,
I'll look into it as soon as i a little time!
I'll look into it as soon as i a little time!
ASKER
Hi Roads,
So i put this:
$test = showMyTitle();
echo "$test";
in my image's alt-tag?
and this:
if(isset($SEARCH)){
$NAVIGATION->outputPageTit le($SEARCH );
}else{
$NAVIGATION->outputPageTit le();
}
where i want the page title?
if i do so, the <title> and <meta> of the page are generated correctly, but then, when the page start loading and reaches the point of loading the image with the alt-text, the page rendering stops and the page isn't displayed any further.
thanks
So i put this:
$test = showMyTitle();
echo "$test";
in my image's alt-tag?
and this:
if(isset($SEARCH)){
$NAVIGATION->outputPageTit
}else{
$NAVIGATION->outputPageTit
}
where i want the page title?
if i do so, the <title> and <meta> of the page are generated correctly, but then, when the page start loading and reaches the point of loading the image with the alt-text, the page rendering stops and the page isn't displayed any further.
thanks
ASKER
i get this error:
Fatal error: Call to undefined function showMyTitle() in D:\xxxxxxxxx\header.php on line 19
Fatal error: Call to undefined function showMyTitle() in D:\xxxxxxxxx\header.php on line 19
Did you include this part of the code: ?
public function showMyTitle(){
return $this->mytitle;
}
ASKER
yes i did.. i copied the whole code you provided
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Wow, works like a charm! Great!
Thank you very much for your time and help!
Kind regards!
Thank you very much for your time and help!
Kind regards!
Thanks.
Remember, that this works for the case of NAVIGATION_NORMAL, if there should be NAVIGATION_SEARCH, you would have to add $this->mytitle for that case after each echo as it is in NAVIGATION_NORMAL.
Remember, that this works for the case of NAVIGATION_NORMAL, if there should be NAVIGATION_SEARCH, you would have to add $this->mytitle for that case after each echo as it is in NAVIGATION_NORMAL.
ASKER
aha, oke. thanks for noticing.
i think i can fix that myself now.
would the echoing of the text of "NAVIGATION_SEARCH" still be done with: $test = $NAVIGATION->showMyTitle() ; echo $test; ?
i think i can fix that myself now.
would the echoing of the text of "NAVIGATION_SEARCH" still be done with: $test = $NAVIGATION->showMyTitle()
Yes.
<?php
$test="<title> xxxxxxxx </title>";
echo "'".trim(strip_tags($test)
?>