How to determine from the formula that there is a phenyl group present in the molecule? Why is the organic compound $\ce{C6H5-CH=CH-CH2Cl}$ named 3-chloro-1-phenylprop-1-ene and not 9-chloronon-5,7-dien-1,3-yne even though there is no specification whatsoever that there is a phenyl group in the organic molecule?
$$\ce{C6H5-CH=CH-CH2Cl}$$
can also be written as
$$\ce{CH#C-C#C-CH=CH-CH=CH-CH2-Cl}$$
and the name for this organic compound would be 9-chloronon-5,7-dien-1,3-yne.
How do we surely know that there exists a phenyl group in the molecule?
Also why is phenyl treated as a substituent and cannot be considered in the longest chain?
It's a matter of convention.

$\ce{C6H5}$ is conventionally used to represent phenyl because it is a common moiety. Your long, highly unsaturated, chain is also $\ce{C6H5}$, but it wouldn't conventionally be written like that without expansion, unless you're setting out to confuse someone.