Skip to content

Instantly share code, notes, and snippets.

@jdmunro
Created November 21, 2008 17:58
Show Gist options
  • Save jdmunro/27521 to your computer and use it in GitHub Desktop.
Save jdmunro/27521 to your computer and use it in GitHub Desktop.
Strips certain HTML tags out of a buffer
void stripHtmlTag( char* htmlBuffer, char* openTag, char* closeTag )
{
char tmpBuffer[HTTP_RESPONSE_SIZE] = "";
char* start = NULL;
char* end = NULL;
char* p = NULL;
int bytes = -1;
p = htmlBuffer;
while( (start = strstr(p,openTag)) != NULL ) {
// Find the closing tag
end = strstr(start,closeTag);
// There isn't a matching tag, bad!
if( end == NULL ) {
strncat(tmpBuffer,p,strlen(p));
break;
}
// Copy up until the start of the tag
bytes = (int)( start - p );
strncat(tmpBuffer,p,bytes);
// Advance the pointer
start += strlen(openTag);
// Copy the text from inbetween the tags
bytes = (int)( end - start );
strncat(tmpBuffer,start,bytes);
// Advance the pointer
p += (int)( (end + strlen(closeTag)) - p );
}
// No tags were found
if( strlen(tmpBuffer) == 0 ) {
return;
}
// Blank the old contents
memset(htmlBuffer,0,sizeof(htmlBuffer));
strcpy(htmlBuffer,tmpBuffer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment