pixeldesigner Posted January 15, 2012 Share Posted January 15, 2012 Using php, how can I replace spaces with hyphens (-) but only do this for the text within the title="" attribute of a specific set of links? Example: I have 2 sets of links and i want to replace the spaces within the title="" attribute but only on the links in the second div, not the first. <div class="set1"> <a href="#" title="THIS IS THE TITLE"> <a href="#" title="THIS IS THE TITLE"> </div> <div class="set2"> <a href="#" title="THIS IS THE TITLE"> <a href="#" title="THIS IS THE TITLE"> </div> Is this possible? would like it to look like this: <div class="set2"> <a href="#" title="THIS-IS-THE-TITLE"> <a href="#" title="THIS-IS-THE-TITLE"> </div> Link to comment https://forums.phpfreaks.com/topic/255052-removing-spaces-within-the-title-attribute/ Share on other sites More sharing options...
Porl123 Posted January 15, 2012 Share Posted January 15, 2012 Would str_replace(' ', '-', $string) be sufficient? Link to comment https://forums.phpfreaks.com/topic/255052-removing-spaces-within-the-title-attribute/#findComment-1307813 Share on other sites More sharing options...
pixeldesigner Posted January 15, 2012 Author Share Posted January 15, 2012 yes but how do I make $string target the title attribute only? in that specific div? Link to comment https://forums.phpfreaks.com/topic/255052-removing-spaces-within-the-title-attribute/#findComment-1307817 Share on other sites More sharing options...
trq Posted January 15, 2012 Share Posted January 15, 2012 Is this data coming form a database or something or are these links actually within a file? Link to comment https://forums.phpfreaks.com/topic/255052-removing-spaces-within-the-title-attribute/#findComment-1307839 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.